webapp/src/components/Pages/AuthorPage.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-11-14 17:41:05 +00:00
import { PageWrap } from '../_shared/PageWrap'
import { AuthorView, PRERENDERED_ARTICLES_COUNT } from '../Views/Author'
2022-09-22 09:37:49 +00:00
import type { PageProps } from '../types'
2022-10-05 15:11:14 +00:00
import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js'
2022-11-18 02:23:04 +00:00
import { loadShouts, resetSortedArticles } from '../../stores/zine/articles'
2022-10-05 15:11:14 +00:00
import { useRouter } from '../../stores/router'
import { loadAuthor } from '../../stores/zine/authors'
2022-10-09 10:56:39 +00:00
import { Loading } from '../Loading'
2022-09-22 09:37:49 +00:00
export const AuthorPage = (props: PageProps) => {
const [isLoaded, setIsLoaded] = createSignal(Boolean(props.shouts) && Boolean(props.author))
2022-10-05 15:11:14 +00:00
const slug = createMemo(() => {
2022-10-25 16:25:42 +00:00
const { page: getPage } = useRouter()
2022-10-05 15:11:14 +00:00
const page = getPage()
if (page.route !== 'author') {
throw new Error('ts guard')
}
return page.params.slug
})
onMount(async () => {
if (isLoaded()) {
return
}
2022-11-18 02:23:04 +00:00
await loadShouts({ filters: { author: slug() }, limit: PRERENDERED_ARTICLES_COUNT })
2022-10-05 15:11:14 +00:00
await loadAuthor({ slug: slug() })
setIsLoaded(true)
})
onCleanup(() => resetSortedArticles())
2022-09-22 09:37:49 +00:00
return (
<PageWrap>
2022-10-09 10:56:39 +00:00
<Show when={isLoaded()} fallback={<Loading />}>
2022-11-15 14:24:50 +00:00
<AuthorView author={props.author} shouts={props.shouts} authorSlug={slug()} />
2022-10-05 15:11:14 +00:00
</Show>
</PageWrap>
2022-09-22 09:37:49 +00:00
)
}
// for lazy loading
export default AuthorPage