2022-09-14 14:40:33 +00:00
|
|
|
import { createEffect, createMemo, createSignal, Show, Suspense } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { FullArticle } from '../Article/FullArticle'
|
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
|
|
|
|
import type { Reaction, Shout } from '../../graphql/types.gen'
|
|
|
|
import { useCurrentArticleStore } from '../../stores/zine/currentArticle'
|
|
|
|
import { loadArticleReactions, useReactionsStore } from '../../stores/zine/reactions'
|
|
|
|
|
|
|
|
import '../../styles/Article.scss'
|
2022-09-14 14:21:26 +00:00
|
|
|
import { useStore } from '@nanostores/solid'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
interface ArticlePageProps {
|
|
|
|
article: Shout
|
|
|
|
slug: string
|
|
|
|
reactions?: Reaction[]
|
|
|
|
}
|
|
|
|
|
|
|
|
const ARTICLE_COMMENTS_PAGE_SIZE = 50
|
|
|
|
|
|
|
|
export const ArticlePage = (props: ArticlePageProps) => {
|
2022-09-13 09:59:04 +00:00
|
|
|
const { getCurrentArticle } = useCurrentArticleStore({ currentArticle: props.article })
|
2022-09-09 11:53:35 +00:00
|
|
|
const [getCommentsPage] = createSignal(1)
|
|
|
|
const [getIsCommentsLoading, setIsCommentsLoading] = createSignal(false)
|
2022-09-14 14:40:33 +00:00
|
|
|
const slug = createMemo(() => props.slug)
|
2022-09-09 11:53:35 +00:00
|
|
|
const reactionslist = useReactionsStore(props.reactions)
|
|
|
|
|
|
|
|
createEffect(async () => {
|
|
|
|
try {
|
|
|
|
setIsCommentsLoading(true)
|
|
|
|
await loadArticleReactions({
|
|
|
|
articleSlug: props.slug,
|
2022-09-14 11:29:10 +00:00
|
|
|
limit: ARTICLE_COMMENTS_PAGE_SIZE,
|
|
|
|
offset: getCommentsPage() * ARTICLE_COMMENTS_PAGE_SIZE
|
2022-09-09 11:53:35 +00:00
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
setIsCommentsLoading(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="article-page">
|
|
|
|
<Show fallback={<div class="center">{t('Loading')}</div>} when={getCurrentArticle()}>
|
|
|
|
<Suspense>
|
|
|
|
<FullArticle
|
|
|
|
article={getCurrentArticle()}
|
|
|
|
reactions={reactionslist().filter((r) => r.shout.slug === slug())}
|
|
|
|
isCommentsLoading={getIsCommentsLoading()}
|
|
|
|
/>
|
|
|
|
</Suspense>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|