webapp/src/pages/article.page.tsx

70 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-11-28 13:18:25 +00:00
import type { Shout } from '../graphql/schema/core.gen'
2024-02-04 11:25:21 +00:00
import type { PageProps } from './types'
import { redirectPage } from '@nanostores/router'
2024-02-04 11:25:21 +00:00
import { Show, createMemo, createSignal, onMount } from 'solid-js'
2024-02-04 11:25:21 +00:00
import { FullArticle } from '../components/Article/FullArticle'
2023-02-17 09:21:02 +00:00
import { Loading } from '../components/_shared/Loading'
import { PageLayout } from '../components/_shared/PageLayout'
import { ReactionsProvider } from '../context/reactions'
import { router, useRouter } from '../stores/router'
import { loadShout, useArticlesStore } from '../stores/zine/articles'
import { setPageLoadManagerPromise } from '../utils/pageLoadManager'
2023-02-17 09:21:02 +00:00
export const ArticlePage = (props: PageProps) => {
const shouts = props.article ? [props.article] : []
const { page } = useRouter()
2023-02-17 09:21:02 +00:00
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 { articleEntities } = useArticlesStore({
shouts,
2023-02-17 09:21:02 +00:00
})
const article = createMemo<Shout>(() => articleEntities()[slug()])
onMount(async () => {
if (!article() || !article().body) {
const loadShoutPromise = loadShout(slug())
setPageLoadManagerPromise(loadShoutPromise)
await loadShoutPromise
2023-11-04 13:40:55 +00:00
if (!article()) {
redirectPage(router, 'fourOuFour')
}
2023-02-17 09:21:02 +00:00
}
})
onMount(() => {
2023-12-10 13:59:50 +00:00
try {
2024-01-23 00:43:08 +00:00
// document.body.appendChild(script)
console.debug('TODO: connect ga')
2023-12-14 00:04:07 +00:00
} catch (error) {
console.warn(error)
2023-12-10 13:59:50 +00:00
}
2023-02-17 09:21:02 +00:00
})
2023-04-17 10:31:20 +00:00
const [scrollToComments, setScrollToComments] = createSignal<boolean>(false)
2023-02-17 09:21:02 +00:00
return (
2023-04-17 10:31:20 +00:00
<PageLayout
title={props.seo?.title}
2023-04-17 10:31:20 +00:00
headerTitle={article()?.title || ''}
slug={article()?.slug}
articleBody={article()?.body}
cover={article()?.cover}
scrollToComments={(value) => {
setScrollToComments(value)
}}
>
2023-02-17 09:21:02 +00:00
<ReactionsProvider>
<Show when={Boolean(article())} fallback={<Loading />}>
2023-04-17 10:31:20 +00:00
<FullArticle article={article()} scrollToComments={scrollToComments()} />
2023-02-17 09:21:02 +00:00
</Show>
</ReactionsProvider>
</PageLayout>
)
}
export const Page = ArticlePage