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'
|
2023-02-28 17:35:33 +00:00
|
|
|
import { ReactionsProvider } from '../context/reactions'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const HomePage = (props: PageProps) => {
|
2023-09-15 14:41:11 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeShouts))
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t } = useLocalize()
|
2022-10-05 15:11:14 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-27 18:50:13 +00:00
|
|
|
await Promise.all([
|
|
|
|
loadShouts({ filters: { visibility: 'public' }, limit: PRERENDERED_ARTICLES_COUNT }),
|
|
|
|
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-09-15 14:41:11 +00:00
|
|
|
<PageLayout withPadding={true}>
|
2023-02-28 17:35:33 +00:00
|
|
|
<ReactionsProvider>
|
|
|
|
<Title>{t('Discours')}</Title>
|
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
2023-09-15 14:41:11 +00:00
|
|
|
<HomeView shouts={props.homeShouts || []} />
|
2023-02-28 17:35:33 +00:00
|
|
|
</Show>
|
|
|
|
</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 = HomePage
|