2022-09-22 09:37:49 +00:00
|
|
|
import { MainLayout } from '../Layouts/MainLayout'
|
|
|
|
import { AuthorView } from '../Views/Author'
|
|
|
|
import type { PageProps } from '../types'
|
2022-10-05 15:11:14 +00:00
|
|
|
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
|
|
|
|
import { loadArticlesForAuthors, resetSortedArticles } from '../../stores/zine/articles'
|
|
|
|
import { useRouter } from '../../stores/router'
|
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
import { loadAuthor } from '../../stores/zine/authors'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
export const AuthorPage = (props: PageProps) => {
|
2022-10-05 15:11:14 +00:00
|
|
|
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.authorArticles) && Boolean(props.author))
|
|
|
|
|
|
|
|
const slug = createMemo(() => {
|
|
|
|
const { getPage } = useRouter()
|
|
|
|
|
|
|
|
const page = getPage()
|
|
|
|
|
|
|
|
if (page.route !== 'author') {
|
|
|
|
throw new Error('ts guard')
|
|
|
|
}
|
|
|
|
|
|
|
|
return page.params.slug
|
|
|
|
})
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
if (isLoaded()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await loadArticlesForAuthors({ authorSlugs: [slug()] })
|
|
|
|
await loadAuthor({ slug: slug() })
|
|
|
|
|
|
|
|
setIsLoaded(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
onCleanup(() => resetSortedArticles())
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
2022-10-05 15:11:14 +00:00
|
|
|
<Show when={isLoaded()} fallback={t('Loading')}>
|
|
|
|
<AuthorView author={props.author} authorArticles={props.authorArticles} authorSlug={slug()} />
|
|
|
|
</Show>
|
2022-09-22 09:37:49 +00:00
|
|
|
</MainLayout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// for lazy loading
|
|
|
|
export default AuthorPage
|