2023-02-17 09:21:02 +00:00
|
|
|
import type { PageProps } from './types'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
import { createEffect, createMemo, createSignal, on, onCleanup, onMount, Show } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
import { Loading } from '../components/_shared/Loading'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { PageLayout } from '../components/_shared/PageLayout'
|
|
|
|
import { AuthorView, PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { ReactionsProvider } from '../context/reactions'
|
2023-11-14 15:10:00 +00:00
|
|
|
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) => {
|
2023-07-19 19:48:24 +00:00
|
|
|
const { page } = useRouter()
|
|
|
|
const slug = createMemo(() => page().params['slug'] as string)
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(
|
2023-11-14 15:10:00 +00:00
|
|
|
Boolean(props.authorShouts) && Boolean(props.author) && props.author.slug === slug(),
|
2023-07-19 19:48:24 +00:00
|
|
|
)
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-09-01 14:28:50 +00:00
|
|
|
const preload = () => {
|
|
|
|
return Promise.all([
|
2023-07-19 19:48:24 +00:00
|
|
|
loadShouts({
|
|
|
|
filters: { author: slug(), visibility: 'community' },
|
2023-11-14 15:10:00 +00:00
|
|
|
limit: PRERENDERED_ARTICLES_COUNT,
|
2023-07-19 19:48:24 +00:00
|
|
|
}),
|
2023-11-14 15:10:00 +00:00
|
|
|
loadAuthor({ slug: slug() }),
|
2023-07-19 19:48:24 +00:00
|
|
|
])
|
2023-09-01 14:28:50 +00:00
|
|
|
}
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-14 10:53:06 +00:00
|
|
|
resetSortedArticles()
|
2023-07-19 19:48:24 +00:00
|
|
|
await preload()
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
createEffect(
|
|
|
|
on(
|
|
|
|
() => slug(),
|
|
|
|
async () => {
|
|
|
|
setIsLoaded(false)
|
|
|
|
resetSortedArticles()
|
|
|
|
await preload()
|
|
|
|
setIsLoaded(true)
|
2023-09-01 14:28:50 +00:00
|
|
|
},
|
2023-11-14 15:10:00 +00:00
|
|
|
{ defer: true },
|
|
|
|
),
|
2023-07-19 19:48:24 +00:00
|
|
|
)
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2023-07-19 19:48:24 +00:00
|
|
|
const usePrerenderedData = props.author?.slug === slug()
|
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
return (
|
2023-11-14 10:45:44 +00:00
|
|
|
<PageLayout title={props.seo.title}>
|
2023-02-17 09:21:02 +00:00
|
|
|
<ReactionsProvider>
|
|
|
|
<Show when={isLoaded()} fallback={<Loading />}>
|
2023-07-19 19:48:24 +00:00
|
|
|
<AuthorView
|
|
|
|
author={usePrerenderedData ? props.author : null}
|
|
|
|
shouts={usePrerenderedData ? props.authorShouts : null}
|
|
|
|
authorSlug={slug()}
|
|
|
|
/>
|
2023-02-17 09:21:02 +00:00
|
|
|
</Show>
|
|
|
|
</ReactionsProvider>
|
|
|
|
</PageLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Page = AuthorPage
|