2024-07-01 13:41:22 +00:00
|
|
|
import { RouteDefinition, RouteLoadFuncArgs, type RouteSectionProps, createAsync } from '@solidjs/router'
|
2024-07-06 00:59:01 +00:00
|
|
|
import { Suspense, createReaction } from 'solid-js'
|
2024-07-01 13:41:22 +00:00
|
|
|
import { AllAuthors } from '~/components/Views/AllAuthors'
|
2024-07-06 00:59:01 +00:00
|
|
|
import { AUTHORS_PER_PAGE } from '~/components/Views/AllAuthors/AllAuthors'
|
2024-07-03 21:25:03 +00:00
|
|
|
import { Loading } from '~/components/_shared/Loading'
|
|
|
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
2024-07-05 22:45:42 +00:00
|
|
|
import { useAuthors } from '~/context/authors'
|
2024-07-03 21:25:03 +00:00
|
|
|
import { useLocalize } from '~/context/localize'
|
|
|
|
import { ReactionsProvider } from '~/context/reactions'
|
2024-07-06 00:59:01 +00:00
|
|
|
import { loadAuthors, loadAuthorsAll } from '~/graphql/api/public'
|
|
|
|
import { Author, AuthorsBy } from '~/graphql/schema/core.gen'
|
2024-07-01 13:41:22 +00:00
|
|
|
|
2024-07-06 00:59:01 +00:00
|
|
|
const fetchAuthorsWithStat = async (offset = 0, order?: string) => {
|
|
|
|
const by: AuthorsBy = { order }
|
|
|
|
const authorsFetcher = loadAuthors({ by, offset, limit: AUTHORS_PER_PAGE })
|
|
|
|
return await authorsFetcher()
|
2024-07-01 13:41:22 +00:00
|
|
|
}
|
2024-07-06 00:59:01 +00:00
|
|
|
|
|
|
|
const fetchAllAuthors = async () => {
|
|
|
|
const authorsAllFetcher = loadAuthorsAll()
|
|
|
|
return await authorsAllFetcher()
|
|
|
|
}
|
|
|
|
|
2024-07-01 13:41:22 +00:00
|
|
|
export const route = {
|
2024-07-06 00:59:01 +00:00
|
|
|
load: ({ location: { query } }: RouteLoadFuncArgs) =>
|
|
|
|
fetchAuthorsWithStat(Number.parseInt(query.offset), query.by || 'name')
|
2024-07-01 13:41:22 +00:00
|
|
|
} 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-06 00:59:01 +00:00
|
|
|
const { authorsSorted, addAuthors } = useAuthors()
|
|
|
|
const authors = createAsync<Author[]>(
|
|
|
|
async () => authorsSorted?.() || props.data.authors || (await fetchAllAuthors())
|
|
|
|
)
|
|
|
|
createReaction(() => typeof addAuthors === 'function' && addAuthors?.(authors() || []))
|
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>
|
|
|
|
)
|
|
|
|
}
|