webapp/src/pages/author.page.tsx
Igor Lobanov 8cad60bdda
Feature/progressive image (#322)
* progressive image

* progressive image v0.2

* progressive images v0.3

* SimplifiedEditor async load, hydration script moved to the bottom

* GrowingTextarea optimization

* static images moved to storj

---------

Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
2023-11-18 15:10:02 +01:00

75 lines
1.9 KiB
TypeScript

import type { PageProps } from './types'
import { createEffect, createMemo, createSignal, on, onCleanup, onMount, Show } from 'solid-js'
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { AuthorView, PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author'
import { ReactionsProvider } from '../context/reactions'
import { useRouter } from '../stores/router'
import { loadShouts, resetSortedArticles } from '../stores/zine/articles'
import { loadAuthor } from '../stores/zine/authors'
export const AuthorPage = (props: PageProps) => {
const { page } = useRouter()
const slug = createMemo(() => page().params['slug'] as string)
const [isLoaded, setIsLoaded] = createSignal(
Boolean(props.authorShouts) && Boolean(props.author) && props.author.slug === slug(),
)
const preload = () => {
return Promise.all([
loadShouts({
filters: { author: slug(), visibility: 'community' },
limit: PRERENDERED_ARTICLES_COUNT,
}),
loadAuthor({ slug: slug() }),
])
}
onMount(async () => {
if (isLoaded()) {
return
}
resetSortedArticles()
await preload()
setIsLoaded(true)
})
createEffect(
on(
() => slug(),
async () => {
setIsLoaded(false)
resetSortedArticles()
await preload()
setIsLoaded(true)
},
{ defer: true },
),
)
onCleanup(() => resetSortedArticles())
const usePrerenderedData = props.author?.slug === slug()
return (
<PageLayout title={props.seo?.title}>
<ReactionsProvider>
<Show when={isLoaded()} fallback={<Loading />}>
<AuthorView
author={usePrerenderedData ? props.author : null}
shouts={usePrerenderedData ? props.authorShouts : null}
authorSlug={slug()}
/>
</Show>
</ReactionsProvider>
</PageLayout>
)
}
export const Page = AuthorPage