webapp/src/pages/index.page.tsx

42 lines
1.3 KiB
TypeScript
Raw Normal View History

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) => {
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
}
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 (
<PageLayout withPadding={true}>
2023-02-28 17:35:33 +00:00
<ReactionsProvider>
<Title>{t('Discours')}</Title>
<Show when={isLoaded()} fallback={<Loading />}>
<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