diff --git a/codegen.yml b/codegen.yml index 44d1e541..2219d008 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,5 @@ overwrite: true -schema: 'http://localhost:8080' +schema: 'https://testapi.discours.io' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/public/icons/user-default.svg b/public/icons/user-default.svg new file mode 100644 index 00000000..b51449e1 --- /dev/null +++ b/public/icons/user-default.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index 4bee6c47..870dc134 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -54,7 +54,7 @@ export default (props: {
{comment()?.createdAt}
-
{comment().stat.rating}
+
{comment().stat?.rating || 0}
diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx new file mode 100644 index 00000000..9f1a2f31 --- /dev/null +++ b/src/components/Article/CommentsTree.tsx @@ -0,0 +1,85 @@ +import { For, Show } from 'solid-js/web' +import { useSession } from '../../context/session' +import Comment from './Comment' +import { t } from '../../utils/intl' +import { showModal } from '../../stores/ui' +import styles from '../../styles/Article.module.scss' +import { useReactionsStore } from '../../stores/zine/reactions' +import { createEffect, createMemo, createSignal, onMount, Suspense } from 'solid-js' +import type { Reaction } from '../../graphql/types.gen' + +const ARTICLE_COMMENTS_PAGE_SIZE = 50 +const MAX_COMMENT_LEVEL = 6 + +export const CommentsTree = (props: { shout: string; reactions?: Reaction[] }) => { + const [getCommentsPage, setCommentsPage] = createSignal(0) + const [isCommentsLoading, setIsCommentsLoading] = createSignal(false) + const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) + const { session } = useSession() + const { sortedReactions, loadReactionsBy } = useReactionsStore({ reactions: props.reactions }) + const reactions = createMemo(() => sortedReactions()) // .filter(r => r.shout.slug === props.shout) ) + const loadMore = async () => { + try { + const page = getCommentsPage() + setIsCommentsLoading(true) + + const { hasMore } = await loadReactionsBy({ + by: { shout: props.shout, comment: true }, + limit: ARTICLE_COMMENTS_PAGE_SIZE, + offset: page * ARTICLE_COMMENTS_PAGE_SIZE + }) + setIsLoadMoreButtonVisible(hasMore) + } finally { + setIsCommentsLoading(false) + } + } + const getCommentById = (cid) => reactions().find((r) => r.id === cid) + const getCommentLevel = (c: Reaction, level = 0) => { + if (c && c.replyTo && level < MAX_COMMENT_LEVEL) { + return getCommentLevel(getCommentById(c.replyTo), level + 1) + } + return level + } + onMount(async () => await loadMore()) + return ( + <> + +

+ {t('Comments')} {reactions().length.toString() || ''} +

+ + + {(reaction: Reaction) => ( + + )} + + + + + +
+ + } + > + + + + ) +} diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index d71cb3f6..e954f770 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -1,33 +1,19 @@ import { capitalize } from '../../utils' import './Full.scss' import { Icon } from '../_shared/Icon' -import ArticleComment from './Comment' import { AuthorCard } from '../Author/Card' import { createMemo, createSignal, For, onMount, Show } from 'solid-js' import type { Author, Reaction, Shout } from '../../graphql/types.gen' import { t } from '../../utils/intl' -import { showModal } from '../../stores/ui' import MD from './MD' import { SharePopup } from './SharePopup' -import { useSession } from '../../context/session' import stylesHeader from '../Nav/Header.module.scss' import styles from '../../styles/Article.module.scss' import RatingControl from './RatingControl' import { clsx } from 'clsx' - -const MAX_COMMENT_LEVEL = 6 - -const getCommentLevel = (comment: Reaction, level = 0) => { - if (comment && comment.replyTo && level < MAX_COMMENT_LEVEL) { - return 0 // FIXME: getCommentLevel(commentsById[c.replyTo], level + 1) - } - return level -} - +import { CommentsTree } from './CommentsTree' interface ArticleProps { article: Shout - reactions: Reaction[] - isCommentsLoading: boolean } const formatDate = (date: Date) => { @@ -41,7 +27,6 @@ const formatDate = (date: Date) => { } export const FullArticle = (props: ArticleProps) => { - const { session } = useSession() const formattedDate = createMemo(() => formatDate(new Date(props.article.createdAt))) const [isSharePopupVisible, setIsSharePopupVisible] = createSignal(false) @@ -52,12 +37,6 @@ export const FullArticle = (props: ArticleProps) => { ) 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) const windowHash = window.location.hash if (windowHash?.length > 0) { const comments = document.querySelector(windowHash) @@ -114,11 +93,6 @@ export const FullArticle = (props: ArticleProps) => { -
- - {props.article.stat?.rating || ''} -
-
{props.article.stat?.commented || ''} @@ -153,7 +127,7 @@ export const FullArticle = (props: ArticleProps) => { {/**/}
- {formattedDate} + {formattedDate()}
@@ -187,39 +161,7 @@ export const FullArticle = (props: ArticleProps) => { )}
- - -

- {t('Comments')} {props.reactions?.length.toString() || ''} -

- - r.body)}> - {(reaction) => ( - - )} - -
- - - - -