2022-09-22 09:37:49 +00:00
|
|
|
import { MainLayout } from '../Layouts/MainLayout'
|
|
|
|
import { TopicView } from '../Views/Topic'
|
|
|
|
import type { PageProps } from '../types'
|
2022-10-05 15:11:14 +00:00
|
|
|
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
|
|
|
|
import { loadArticlesForTopics, resetSortedArticles } from '../../stores/zine/articles'
|
|
|
|
import { useRouter } from '../../stores/router'
|
|
|
|
import { loadTopic } from '../../stores/zine/topics'
|
2022-10-09 10:56:39 +00:00
|
|
|
import { Loading } from '../Loading'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const TopicPage = (props: PageProps) => {
|
2022-10-05 15:11:14 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.authorArticles) && Boolean(props.author))
|
|
|
|
|
|
|
|
const slug = createMemo(() => {
|
2022-10-25 16:25:42 +00:00
|
|
|
const { page: getPage } = useRouter()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
const page = getPage()
|
|
|
|
|
2022-10-05 17:55:17 +00:00
|
|
|
if (page.route !== 'topic') {
|
2022-10-05 15:11:14 +00:00
|
|
|
throw new Error('ts guard')
|
|
|
|
}
|
|
|
|
|
|
|
|
return page.params.slug
|
|
|
|
})
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadArticlesForTopics({ topicSlugs: [slug()] })
|
|
|
|
await loadTopic({ slug: slug() })
|
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
2022-10-09 10:56:39 +00:00
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
2022-10-05 15:11:14 +00:00
|
|
|
<TopicView topic={props.topic} topicArticles={props.topicArticles} topicSlug={slug()} />
|
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
</MainLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for lazy loading
|
|
|
|
export default TopicPage
|