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'
|
2024-07-04 07:51:15 +00:00
|
|
|
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'
|
2024-07-04 07:51:15 +00:00
|
|
|
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-05 08:11:57 +00:00
|
|
|
<PageLayout withPadding={true} title={`${t('Discours')} :: ${t('All topics')}`}>
|
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>
|
|
|
|
)
|
|
|
|
}
|