2023-02-17 09:21:02 +00:00
|
|
|
import type { PageProps } from './types'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-02-04 11:25:21 +00:00
|
|
|
import { Show, createEffect, createMemo, createSignal, on, onCleanup, onMount } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2024-02-04 11:25:21 +00:00
|
|
|
import { PRERENDERED_ARTICLES_COUNT, TopicView } from '../components/Views/Topic'
|
2023-12-21 12:48:13 +00:00
|
|
|
import { Loading } from '../components/_shared/Loading'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { PageLayout } from '../components/_shared/PageLayout'
|
2023-02-28 17:35:33 +00:00
|
|
|
import { ReactionsProvider } from '../context/reactions'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { useRouter } from '../stores/router'
|
|
|
|
import { loadShouts, resetSortedArticles } from '../stores/zine/articles'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const TopicPage = (props: PageProps) => {
|
2023-07-19 19:48:24 +00:00
|
|
|
const { page } = useRouter()
|
2024-02-04 09:30:06 +00:00
|
|
|
const slug = createMemo(() => page().params['slug'] as string)
|
2022-10-05 15:11:14 +00:00
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(
|
2023-11-14 15:10:00 +00:00
|
|
|
Boolean(props.topicShouts) && Boolean(props.topic) && props.topic.slug === slug(),
|
2023-07-19 19:48:24 +00:00
|
|
|
)
|
2023-12-21 12:48:13 +00:00
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
const preload = () =>
|
|
|
|
Promise.all([
|
2023-12-25 15:07:12 +00:00
|
|
|
loadShouts({
|
2024-02-02 17:29:53 +00:00
|
|
|
filters: { topic: slug(), featured: true },
|
2023-12-25 15:07:12 +00:00
|
|
|
limit: PRERENDERED_ARTICLES_COUNT,
|
|
|
|
offset: 0,
|
|
|
|
}),
|
2023-07-19 19:48:24 +00:00
|
|
|
])
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
await preload()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
createEffect(
|
|
|
|
on(
|
|
|
|
() => slug(),
|
|
|
|
async () => {
|
|
|
|
setIsLoaded(false)
|
|
|
|
resetSortedArticles()
|
|
|
|
await preload()
|
|
|
|
setIsLoaded(true)
|
2023-09-01 14:28:50 +00:00
|
|
|
},
|
2023-11-14 15:10:00 +00:00
|
|
|
{ defer: true },
|
|
|
|
),
|
2023-07-19 19:48:24 +00:00
|
|
|
)
|
|
|
|
|
2022-10-05 15:11:14 +00:00
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
const usePrerenderedData = props.topic?.slug === slug()
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
2023-12-21 12:48:13 +00:00
|
|
|
<PageLayout title={props.seo.title}>
|
2023-02-28 17:35:33 +00:00
|
|
|
<ReactionsProvider>
|
2023-12-21 12:48:13 +00:00
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
|
|
|
<TopicView
|
|
|
|
topic={usePrerenderedData ? props.topic : null}
|
|
|
|
shouts={usePrerenderedData ? props.topicShouts : null}
|
|
|
|
topicSlug={slug()}
|
|
|
|
/>
|
|
|
|
</Show>
|
2023-02-28 17:35:33 +00:00
|
|
|
</ReactionsProvider>
|
2023-02-17 09:21:02 +00:00
|
|
|
</PageLayout>
|
2022-09-22 09:37:49 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
export const Page = TopicPage
|