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-09-22 09:37:49 +00:00
|
|
|
import type { Shout } from '../../graphql/types.gen'
|
2022-09-09 11:53:35 +00:00
|
|
|
import { loadArticleReactions, useReactionsStore } from '../../stores/zine/reactions'
|
|
|
|
|
|
|
|
import '../../styles/Article.scss'
|
|
|
|
|
|
|
|
interface ArticlePageProps {
|
|
|
|
article: Shout
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-22 09:37:49 +00:00
|
|
|
const reactionslist = useReactionsStore()
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
createEffect(async () => {
|
|
|
|
try {
|
|
|
|
setIsCommentsLoading(true)
|
|
|
|
await loadArticleReactions({
|
2022-09-22 09:37:49 +00:00
|
|
|
articleSlug: 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}
|
|
|
|
reactions={reactionslist().filter((r) => r.shout.slug === props.article.slug)}
|
2022-09-09 11:53:35 +00:00
|
|
|
isCommentsLoading={getIsCommentsLoading()}
|
|
|
|
/>
|
|
|
|
</Suspense>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|