webapp/src/routes/topic/(all-topics).tsx

39 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-06-28 15:05:45 +00:00
import { type RouteDefinition, type RouteSectionProps, createAsync } from '@solidjs/router'
2024-06-28 15:26:00 +00:00
import { Suspense, createEffect } from 'solid-js'
import { AllTopics } from '~/components/Views/AllTopics'
import { Loading } from '~/components/_shared/Loading'
import { PageLayout } from '~/components/_shared/PageLayout'
import { useLocalize } from '~/context/localize'
import { ReactionsProvider } from '~/context/reactions'
2024-06-28 15:05:45 +00:00
import { useTopics } from '~/context/topics'
import { loadTopics } from '~/graphql/api/public'
2024-06-28 15:05:45 +00:00
import { Topic } from '~/graphql/schema/core.gen'
2024-06-24 17:50:27 +00:00
const fetchData = async () => {
const topicsFetcher = loadTopics()
return await topicsFetcher()
}
export const route = { load: loadTopics } satisfies RouteDefinition
2024-07-05 17:23:07 +00:00
export default (props: RouteSectionProps<{ topics: Topic[] }>) => {
2024-06-24 17:50:27 +00:00
const { t } = useLocalize()
const topics = createAsync<Topic[]>(async () => props.data.topics || (await fetchData()) || [])
2024-06-28 15:05:45 +00:00
const { addTopics } = useTopics()
2024-06-28 15:26:00 +00:00
createEffect(() => addTopics(topics() || []))
2024-06-24 17:50:27 +00:00
return (
2024-07-09 09:13:13 +00:00
<PageLayout
withPadding={true}
key="topics"
title={`${t('Discours')} :: ${t('All topics')}`}
desc="Thematic table of contents of the magazine. Here you can find all the topics that the community authors wrote about"
>
2024-06-24 17:50:27 +00:00
<ReactionsProvider>
<Suspense fallback={<Loading />}>
2024-07-01 15:30:45 +00:00
<AllTopics topics={topics() as Topic[]} />
2024-06-24 17:50:27 +00:00
</Suspense>
</ReactionsProvider>
</PageLayout>
)
}