webapp/src/routes/author/(all-authors).tsx

61 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-07-01 13:41:22 +00:00
import { RouteDefinition, RouteLoadFuncArgs, type RouteSectionProps, createAsync } from '@solidjs/router'
2024-07-05 22:24:22 +00:00
import { Suspense } from 'solid-js'
2024-07-01 13:41:22 +00:00
import { AllAuthors } from '~/components/Views/AllAuthors'
2024-07-03 21:25:03 +00:00
import { Loading } from '~/components/_shared/Loading'
import { PageLayout } from '~/components/_shared/PageLayout'
import { useLocalize } from '~/context/localize'
import { ReactionsProvider } from '~/context/reactions'
import { loadAuthors } from '~/graphql/api/public'
2024-07-01 13:41:22 +00:00
import { Author, QueryLoad_Authors_ByArgs } from '~/graphql/schema/core.gen'
const fetchData = async () => {
const opts: QueryLoad_Authors_ByArgs = {
by: {
after: undefined,
created_at: undefined,
last_seen: undefined,
name: undefined,
order: undefined,
slug: undefined,
stat: undefined,
topic: undefined
}
}
const topicsFetcher = loadAuthors(opts)
return await topicsFetcher()
}
const AUTHORS_PER_PAGE = 20
export const route = {
load: (_args: RouteLoadFuncArgs) => {
const opts: QueryLoad_Authors_ByArgs = {
by: {
after: undefined,
created_at: undefined,
last_seen: undefined,
name: undefined,
order: undefined,
slug: undefined,
stat: undefined,
topic: undefined
},
limit: AUTHORS_PER_PAGE,
offset: 0
}
return loadAuthors(opts)
}
} satisfies RouteDefinition
2024-07-05 08:11:57 +00:00
export default function AllAuthorsPage(props: RouteSectionProps<{ authors: Author[] }>) {
2024-07-01 13:41:22 +00:00
const { t } = useLocalize()
2024-07-05 22:24:56 +00:00
const authors = createAsync<Author[]>(async () => props.data.authors || (await fetchData()))
2024-07-01 13:41:22 +00:00
return (
2024-07-05 08:11:57 +00:00
<PageLayout withPadding={true} title={`${t('Discours')} :: ${t('All authors')}`}>
2024-07-01 13:41:22 +00:00
<ReactionsProvider>
<Suspense fallback={<Loading />}>
2024-07-03 07:02:46 +00:00
<AllAuthors authors={authors() || []} isLoaded={Boolean(authors())} />
2024-07-01 13:41:22 +00:00
</Suspense>
</ReactionsProvider>
</PageLayout>
)
}