2023-02-17 09:21:02 +00:00
|
|
|
import type { PageProps } from './types'
|
2023-11-14 15:10:00 +00:00
|
|
|
import type { Shout } from '../graphql/types.gen'
|
|
|
|
|
|
|
|
import { redirectPage } from '@nanostores/router'
|
|
|
|
import { createMemo, createSignal, onMount, Show } from 'solid-js'
|
|
|
|
|
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'
|
2023-03-03 18:26:26 +00:00
|
|
|
import { FullArticle } from '../components/Article/FullArticle'
|
2023-11-14 15:10:00 +00:00
|
|
|
import { ReactionsProvider } from '../context/reactions'
|
|
|
|
import { router, useRouter } from '../stores/router'
|
|
|
|
import { loadShout, useArticlesStore } from '../stores/zine/articles'
|
2023-04-03 14:22:59 +00:00
|
|
|
import { setPageLoadManagerPromise } from '../utils/pageLoadManager'
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
export const ArticlePage = (props: PageProps) => {
|
|
|
|
const shouts = props.article ? [props.article] : []
|
2023-10-16 17:24:33 +00:00
|
|
|
const { page } = useRouter()
|
2023-02-17 09:21:02 +00:00
|
|
|
|
2023-10-16 17:24:33 +00:00
|
|
|
const slug = createMemo(() => page().params['slug'] as string)
|
2023-02-17 09:21:02 +00:00
|
|
|
|
|
|
|
const { articleEntities } = useArticlesStore({
|
2023-11-14 15:10:00 +00:00
|
|
|
shouts,
|
2023-02-17 09:21:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const article = createMemo<Shout>(() => articleEntities()[slug()])
|
|
|
|
|
|
|
|
onMount(async () => {
|
2023-11-14 10:45:44 +00:00
|
|
|
if (!article() || !article().body) {
|
2023-04-03 14:22:59 +00:00
|
|
|
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(() => {
|
|
|
|
const script = document.createElement('script')
|
|
|
|
script.async = true
|
|
|
|
script.src = 'https://ackee.discours.io/increment.js'
|
|
|
|
script.dataset.ackeeServer = 'https://ackee.discours.io'
|
|
|
|
script.dataset.ackeeDomainId = '1004abeb-89b2-4e85-ad97-74f8d2c8ed2d'
|
|
|
|
document.body.appendChild(script)
|
|
|
|
})
|
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
|
2023-11-14 10:45:44 +00:00
|
|
|
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
|