2022-10-05 15:11:14 +00:00
|
|
|
import { createSignal, onCleanup, onMount, Show } from 'solid-js'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { Title } from '@solidjs/meta'
|
|
|
|
import { HomeView, PRERENDERED_ARTICLES_COUNT, RANDOM_TOPICS_COUNT } from '../components/Views/Home'
|
|
|
|
import { PageLayout } from '../components/_shared/PageLayout'
|
|
|
|
import type { PageProps } from './types'
|
|
|
|
import { loadShouts, resetSortedArticles } from '../stores/zine/articles'
|
|
|
|
import { loadRandomTopics } from '../stores/zine/topics'
|
|
|
|
import { Loading } from '../components/_shared/Loading'
|
|
|
|
import { useLocalize } from '../context/localize'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const HomePage = (props: PageProps) => {
|
2022-12-07 19:49:03 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeShouts) && Boolean(props.randomTopics))
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-22 03:02:11 +00:00
|
|
|
await loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT })
|
|
|
|
await loadRandomTopics({ amount: RANDOM_TOPICS_COUNT })
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
2023-02-17 09:21:02 +00:00
|
|
|
<PageLayout withPadding={true}>
|
|
|
|
<Title>{t('Discours')}</Title>
|
2022-10-09 10:56:39 +00:00
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
2022-12-07 19:49:03 +00:00
|
|
|
<HomeView randomTopics={props.randomTopics} shouts={props.homeShouts || []} />
|
2022-10-05 15:11:14 +00:00
|
|
|
</Show>
|
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 = HomePage
|