2022-09-22 09:37:49 +00:00
|
|
|
import { HomeView } from '../Views/Home'
|
|
|
|
import { MainLayout } from '../Layouts/MainLayout'
|
|
|
|
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-10-05 15:11:14 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeArticles) && Boolean(props.randomTopics))
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadPublishedArticles({ limit: 5, offset: 0 })
|
|
|
|
await loadRandomTopics()
|
|
|
|
|
|
|
|
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
|
|
|
<HomeView randomTopics={props.randomTopics} recentPublishedArticles={props.homeArticles || []} />
|
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
</MainLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for lazy loading
|
|
|
|
export default HomePage
|