From e0425f97b86feaf31107337ad6ed96ccfbe1e463 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:20:36 +0800 Subject: [PATCH 1/3] fix(ArticleComment): fix comment count cache --- .../CommentForm/index.tsx | 20 --------------- .../Forms/ArticleCommentForm/index.tsx | 25 +------------------ 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/src/components/Dialogs/ArticleCommentFormDialog/CommentForm/index.tsx b/src/components/Dialogs/ArticleCommentFormDialog/CommentForm/index.tsx index db6e5a1a59..4ab5bca237 100644 --- a/src/components/Dialogs/ArticleCommentFormDialog/CommentForm/index.tsx +++ b/src/components/Dialogs/ArticleCommentFormDialog/CommentForm/index.tsx @@ -9,13 +9,11 @@ import { SpinnerBlock, useEventListener, useMutation, - useRoute, ViewerContext, } from '~/components' import { PUT_ARTICLE_COMMENT } from '~/components/GQL/mutations/putComment' import { updateArticleComments, - updateArticlePublic, updateCommentDetail, } from '~/components/GQL/updates' import { PutArticleCommentMutation } from '~/gql/graphql' @@ -54,8 +52,6 @@ const CommentForm: React.FC = ({ }) => { const viewer = useContext(ViewerContext) const formRef = useRef(null) - const { getQuery, routerLang } = useRoute() - const shortHash = getQuery('shortHash') const [putComment] = useMutation(PUT_ARTICLE_COMMENT) @@ -120,22 +116,6 @@ const CommentForm: React.FC = ({ comment: mutationResult.data?.putComment, }) } - - if (!!parentId) { - updateArticlePublic({ - cache, - shortHash, - routerLang, - type: 'addSecondaryComment', - }) - } else { - updateArticlePublic({ - cache, - shortHash, - routerLang, - type: 'addComment', - }) - } }, }) diff --git a/src/components/Forms/ArticleCommentForm/index.tsx b/src/components/Forms/ArticleCommentForm/index.tsx index b098a1173e..00321ce7b6 100644 --- a/src/components/Forms/ArticleCommentForm/index.tsx +++ b/src/components/Forms/ArticleCommentForm/index.tsx @@ -15,15 +15,10 @@ import { useCommentEditorContext, useEventListener, useMutation, - useRoute, ViewerContext, } from '~/components' import CommentEditor from '~/components/Editor/Comment' -import { - updateArticleComments, - updateArticlePublic, - updateCommentDetail, -} from '~/components/GQL' +import { updateArticleComments, updateCommentDetail } from '~/components/GQL' import { PUT_ARTICLE_COMMENT } from '~/components/GQL/mutations/putComment' import { PutArticleCommentMutation } from '~/gql/graphql' @@ -63,14 +58,12 @@ export const ArticleCommentForm: React.FC = ({ }) => { const intl = useIntl() const viewer = useContext(ViewerContext) - const { getQuery, routerLang } = useRoute() const { setActiveEditor } = useCommentEditorContext() const [editor, localSetEditor] = useState(null) const setEditor = (editor: Editor | null) => { localSetEditor(editor) propsSetEditor?.(editor) } - const shortHash = getQuery('shortHash') const [putComment] = useMutation(PUT_ARTICLE_COMMENT) @@ -136,22 +129,6 @@ export const ArticleCommentForm: React.FC = ({ comment: mutationResult.data?.putComment, }) } - - if (!!parentId) { - updateArticlePublic({ - cache, - shortHash, - routerLang, - type: 'addSecondaryComment', - }) - } else { - updateArticlePublic({ - cache, - shortHash, - routerLang, - type: 'addComment', - }) - } }, }) From 5db16e79d7ddd6b98a5685b5920ccd0b21c88e53 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:43:23 +0800 Subject: [PATCH 2/3] fix(Comment): add commentCount field --- src/components/Comment/FooterActions/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Comment/FooterActions/index.tsx b/src/components/Comment/FooterActions/index.tsx index bad961a5aa..27be351f3b 100644 --- a/src/components/Comment/FooterActions/index.tsx +++ b/src/components/Comment/FooterActions/index.tsx @@ -64,6 +64,7 @@ const fragments = { id isBlocking } + commentCount } ... on Moment { From d01d6f1c50e7621ef2de92f1dfbbd8c1186259f0 Mon Sep 17 00:00:00 2001 From: bluecloud <96812901+pitb2022@users.noreply.github.com> Date: Wed, 4 Sep 2024 15:07:01 +0800 Subject: [PATCH 3/3] fix(articlePublic): remove unused code --- src/components/GQL/updates/articlePublic.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/components/GQL/updates/articlePublic.ts b/src/components/GQL/updates/articlePublic.ts index f34e933746..54da6e07c7 100644 --- a/src/components/GQL/updates/articlePublic.ts +++ b/src/components/GQL/updates/articlePublic.ts @@ -22,12 +22,7 @@ export const updateArticlePublic = ({ routerLang: UserLanguage viewer?: Viewer txId?: string - type: - | 'deleteComment' - | 'addComment' - | 'addSecondaryComment' - | 'deleteSecondaryComment' - | 'updateDonation' + type: 'deleteComment' | 'deleteSecondaryComment' | 'updateDonation' }) => { // FIXME: circular dependencies const { @@ -68,17 +63,10 @@ export const updateArticlePublic = ({ let commentCount = data.article.commentCount let totalCount = data.article.comments.totalCount switch (type) { - case 'addComment': - totalCount += 1 - commentCount += 1 - break case 'deleteComment': totalCount -= 1 commentCount -= 1 break - case 'addSecondaryComment': - commentCount += 1 - break case 'deleteSecondaryComment': commentCount -= 1 break