2022-10-28 21:21:47 +00:00
|
|
|
import { HomeView, PRERENDERED_ARTICLES_COUNT } from '../Views/Home'
|
2022-11-14 17:41:05 +00:00
|
|
|
import { PageWrap } from '../_shared/PageWrap'
|
2022-09-22 09:37:49 +00:00
|
|
|
import type { PageProps } from '../types'
|
2022-10-05 15:11:14 +00:00
|
|
|
import { createSignal, onCleanup, onMount, Show } from 'solid-js'
|
|
|
|
import { loadPublishedArticles, resetSortedArticles } from '../../stores/zine/articles'
|
|
|
|
import { loadRandomTopics } 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 HomePage = (props: PageProps) => {
|
2022-11-13 03:40:37 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.shouts) && Boolean(props.randomTopics))
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-28 21:21:47 +00:00
|
|
|
await loadPublishedArticles({ limit: PRERENDERED_ARTICLES_COUNT, offset: 0 })
|
2022-10-05 15:11:14 +00:00
|
|
|
await loadRandomTopics()
|
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
2022-11-13 03:40:37 +00:00
|
|
|
<PageWrap>
|
2022-10-09 10:56:39 +00:00
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
2022-11-13 03:40:37 +00:00
|
|
|
<HomeView randomTopics={props.randomTopics} recentPublishedArticles={props.shouts || []} />
|
2022-10-05 15:11:14 +00:00
|
|
|
</Show>
|
2022-11-13 03:40:37 +00:00
|
|
|
</PageWrap>
|
2022-09-22 09:37:49 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for lazy loading
|
|
|
|
export default HomePage
|