webapp/src/components/Views/ArticlePage.tsx

54 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-09-09 11:53:35 +00:00
import { createEffect, createSignal, Show, Suspense } from 'solid-js'
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 { slug } from '../../stores/router'
import '../../styles/Article.scss'
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)
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>
)
}