webapp/src/components/Views/Article.tsx

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-09-14 14:44:10 +00:00
import { createEffect, createSignal, Show, Suspense } from 'solid-js'
2022-09-09 11:53:35 +00:00
import { FullArticle } from '../Article/FullArticle'
import { t } from '../../utils/intl'
2022-11-16 06:33:58 +00:00
import type { Shout, Reaction } from '../../graphql/types.gen'
import { useReactionsStore } from '../../stores/zine/reactions'
2022-09-09 11:53:35 +00:00
import '../../styles/Article.scss'
interface ArticlePageProps {
article: Shout
2022-11-16 06:33:58 +00:00
reactions?: Reaction[]
2022-09-09 11:53:35 +00:00
}
const ARTICLE_COMMENTS_PAGE_SIZE = 50
2022-09-22 09:37:49 +00:00
export const ArticleView = (props: ArticlePageProps) => {
2022-09-09 11:53:35 +00:00
const [getCommentsPage] = createSignal(1)
const [getIsCommentsLoading, setIsCommentsLoading] = createSignal(false)
2022-11-21 00:26:20 +00:00
const { reactionsByShout, loadReactionsBy } = useReactionsStore({ reactions: props.reactions })
2022-09-09 11:53:35 +00:00
createEffect(async () => {
try {
setIsCommentsLoading(true)
2022-11-16 06:33:58 +00:00
await loadReactionsBy({
by: { shout: props.article.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">
2022-09-22 09:37:49 +00:00
<Show fallback={<div class="center">{t('Loading')}</div>} when={props.article}>
2022-09-09 11:53:35 +00:00
<Suspense>
<FullArticle
2022-09-22 09:37:49 +00:00
article={props.article}
2022-11-16 06:33:58 +00:00
reactions={reactionsByShout()[props.article.slug]}
2022-09-09 11:53:35 +00:00
isCommentsLoading={getIsCommentsLoading()}
/>
</Suspense>
</Show>
</div>
)
}