webapp/src/pages/author.page.tsx

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import type { PageProps } from './types'
2024-05-20 23:15:52 +00:00
import { Show, createEffect, createMemo, createSignal, on, onCleanup } from 'solid-js'
2024-02-04 11:25:21 +00:00
import { AuthorView, PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author'
2023-02-17 09:21:02 +00:00
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { useLocalize } from '../context/localize'
2023-02-17 09:21:02 +00:00
import { ReactionsProvider } from '../context/reactions'
import { useRouter } from '../stores/router'
import { loadShouts, resetSortedArticles } from '../stores/zine/articles'
import { loadAuthor } from '../stores/zine/authors'
2023-02-17 09:21:02 +00:00
export const AuthorPage = (props: PageProps) => {
const { t } = useLocalize()
const { page } = useRouter()
2024-02-04 09:30:06 +00:00
const slug = createMemo(() => page().params['slug'] as string)
2023-02-17 09:21:02 +00:00
const [isLoaded, setIsLoaded] = createSignal(
Boolean(props.authorShouts) && Boolean(props.author) && props.author.slug === slug(),
)
2023-02-17 09:21:02 +00:00
createEffect(
2024-05-20 23:15:52 +00:00
on(slug, async (s) => {
if (s) {
setIsLoaded(false)
resetSortedArticles()
2024-05-20 23:15:52 +00:00
await loadShouts({
filters: { author: s, featured: false },
limit: PRERENDERED_ARTICLES_COUNT,
})
await loadAuthor({ slug: s })
setIsLoaded(true)
2024-05-20 23:15:52 +00:00
}
}),
)
2023-02-17 09:21:02 +00:00
onCleanup(() => resetSortedArticles())
return (
<PageLayout title={props.seo?.title || t('Discours')}>
2023-02-17 09:21:02 +00:00
<ReactionsProvider>
<Show when={isLoaded()} fallback={<Loading />}>
<AuthorView authorSlug={slug()} />
2023-02-17 09:21:02 +00:00
</Show>
</ReactionsProvider>
</PageLayout>
)
}
export const Page = AuthorPage