Skip to content

Commit

Permalink
Merge branch 'bose/2659' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Nov 7, 2024
2 parents 9b144b2 + 75faad8 commit c937df9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
4 changes: 2 additions & 2 deletions web/lib/queries/newsroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const nextDirectionFilter = /* groq */ `
`

export const allNewsDocuments = /* groq */ `
*[_type == "news" && ${sameLang} && ${noDrafts} ] | order(${publishDateTimeQuery} desc)[0...20] {
*[_type == "news" && ${sameLang} && ${noDrafts} ] | order(${publishDateTimeQuery} desc)[0...30] {
"id": _id,
"updatedAt": _updatedAt,
title,
Expand All @@ -58,7 +58,7 @@ export const getNewsArticlesByPage = (hasFirstId = false, hasLastId = false) =>
*[_type == 'news' && ${sameLang} && ${noDrafts}
${hasLastId ? nextDirectionFilter : ''}
${hasFirstId ? prevDirectionFilter : ''}
] | order(${publishDateTimeQuery} desc)[0...20]{
] | order(${publishDateTimeQuery} desc)[0...30]{
"id": _id,
"updatedAt": _updatedAt,
"slug": slug.current,
Expand Down
55 changes: 19 additions & 36 deletions web/pages/nyheter/index.global.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
import { GetServerSideProps } from 'next'
import { InstantSearchSSRProvider, getServerState } from 'react-instantsearch'
import type { AppProps } from 'next/app'
import { IntlProvider } from 'react-intl'
import Footer from '../../pageComponents/shared/Footer'
import Header from '../../pageComponents/shared/Header'
import { newsroomQuery } from '../../lib/queries/newsroom'
import { allNewsDocuments, newsroomQuery } from '../../lib/queries/newsroom'
import getIntl from '../../common/helpers/getIntl'
import { getNameFromLocale, getIsoFromLocale } from '../../lib/localization'
import { defaultLanguage } from '../../languages'
import { AlgoliaIndexPageType, NewsRoomPageType } from '../../types'
import { getComponentsData } from '../../lib/fetchData'
import { renderToString } from 'react-dom/server'
import NewsRoomTemplate from '@templates/newsroom/Newsroom'
import { getComponentsData, getData } from '../../lib/fetchData'
import NewsRoomTemplateSanity from '@templates/newsroom/sanity/NewsroomSanity'

export default function NorwegianNewsRoom({ isServerRendered = false, serverState, data, url }: AlgoliaIndexPageType) {
export default function NorwegianNewsRoom({ data, url }: AlgoliaIndexPageType) {
const defaultLocale = defaultLanguage.locale
const { pageData, slug, intl } = data
const locale = intl?.locale || defaultLocale

return (
<InstantSearchSSRProvider {...serverState}>
<IntlProvider
locale={getIsoFromLocale(locale)}
defaultLocale={getIsoFromLocale(defaultLocale)}
messages={intl?.messages}
>
<NewsRoomTemplate
isServerRendered={isServerRendered}
locale={locale}
pageData={pageData as NewsRoomPageType}
slug={slug}
url={url}
/>
</IntlProvider>
</InstantSearchSSRProvider>
<IntlProvider
locale={getIsoFromLocale(locale)}
defaultLocale={getIsoFromLocale(defaultLocale)}
messages={intl?.messages}
>
<NewsRoomTemplateSanity locale={locale} pageData={pageData as NewsRoomPageType} slug={slug} url={url} />
</IntlProvider>
)
}

Expand Down Expand Up @@ -93,30 +83,23 @@ export const getServerSideProps: GetServerSideProps = async ({ req, preview = fa
},
preview,
)

const serverState = await getServerState(
<NorwegianNewsRoom
isServerRendered
data={{
intl,
pageData,
slug,
}}
url={url}
/>,
{ renderToString },
)
const { data } = await getData({
query: allNewsDocuments,
queryParams,
})

return {
props: {
locale,
serverState,
url,
data: {
menuData,
footerData,
intl,
pageData,
pageData: {
...pageData,
newsArticles: data,
},
slug,
},
},
Expand Down
7 changes: 6 additions & 1 deletion web/templates/newsroom/sanity/NewsroomSanity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import { List } from '@core/List'
import { PaginationContextProvider } from '../../../common/contexts/PaginationContext'
import NewsSectionsSanity from './NewsSectionsSanity'
import { stringify } from 'querystring'
import { useRouter } from 'next/router'
import { SimplePagination } from '@core/SimplePagination/SimplePagination'
import NewsSectionsSkeleton from '../NewsSections/NewsSectionsSkeleton'
import { getNameFromLocale } from '../../../lib/localization'

type NewsRoomTemplateProps = {
isServerRendered?: boolean
Expand All @@ -35,7 +37,8 @@ const NewsRoomTemplateSanity = forwardRef<HTMLElement, NewsRoomTemplateProps>(fu
fallbackImages,
} = pageData || {}
const intl = useIntl()

const router = useRouter()
const { locale } = router
const resultsRef = useRef<HTMLDivElement>(null)
const [isLoading, setIsLoading] = useState(false)
const [lastId, setLastId] = useState(newsArticles?.length > 0 ? newsArticles[newsArticles?.length - 1]?.id : null)
Expand Down Expand Up @@ -68,6 +71,7 @@ const NewsRoomTemplateSanity = forwardRef<HTMLElement, NewsRoomTemplateProps>(fu
const getNextNews = async () => {
setIsLoading(true)
const query = {
lang: getNameFromLocale(locale),
lastId: lastId,
lastPublishedAt: lastPublished,
}
Expand All @@ -86,6 +90,7 @@ const NewsRoomTemplateSanity = forwardRef<HTMLElement, NewsRoomTemplateProps>(fu
const getPreviousNews = async () => {
setIsLoading(true)
const query = {
lang: getNameFromLocale(locale),
lastId: firstId,
lastPublishedAt: firstPublished,
}
Expand Down

0 comments on commit c937df9

Please sign in to comment.