Refresh comments threads and count on new comment (#276)

* Refresh comments threads and count on new comment

* Fix tests
This commit is contained in:
Charles Bochet
2023-06-12 19:32:18 +02:00
committed by GitHub
parent 3341539eb2
commit 16e1b862d9
17 changed files with 74 additions and 181 deletions

View File

@ -70,8 +70,8 @@ export function CommentThread({ commentThread }: OwnProps) {
// Also it cannot refetch queries than are not in the cache
refetchQueries: [
'GetCommentThreadsByTargets',
'GetPeopleCommentsCount',
'GetCompanyCommentsCount',
'GetCompanies',
'GetPeople',
],
onError: (error) => {
logError(

View File

@ -6,6 +6,7 @@ import { currentUserState } from '@/auth/states/currentUserState';
import { commentableEntityArrayState } from '@/comments/states/commentableEntityArrayState';
import { createdCommentThreadIdState } from '@/comments/states/createdCommentThreadIdState';
import { AutosizeTextInput } from '@/ui/components/inputs/AutosizeTextInput';
import { useOpenRightDrawer } from '@/ui/layout/right-drawer/hooks/useOpenRightDrawer';
import { logError } from '@/utils/logs/logError';
import { isDefined } from '@/utils/type-guards/isDefined';
import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';
@ -49,6 +50,8 @@ export function CommentThreadCreateMode() {
createdCommentThreadIdState,
);
const openRightDrawer = useOpenRightDrawer();
const [createCommentMutation] = useCreateCommentMutation();
const [createCommentThreadWithComment] =
@ -96,9 +99,10 @@ export function CommentThreadCreateMode() {
}),
),
},
refetchQueries: ['GetCommentThread'],
refetchQueries: ['GetCommentThread', 'GetCompanies', 'GetPeople'],
onCompleted(data) {
setCreatedCommentThreadId(data.createOneCommentThread.id);
openRightDrawer('comments');
},
});
} else {
@ -111,11 +115,7 @@ export function CommentThreadCreateMode() {
createdAt: new Date().toISOString(),
},
// TODO: find a way to have this configuration dynamic and typed
refetchQueries: [
'GetCommentThread',
'GetPeopleCommentsCount',
'GetCompanyCommentsCount',
],
refetchQueries: ['GetCommentThread'],
onError: (error) => {
logError(
`In handleCreateCommentThread, createCommentMutation onError, error: ${error}`,

View File

@ -4,7 +4,10 @@ import { CommentThreadForDrawer } from '@/comments/types/CommentThreadForDrawer'
import { RightDrawerBody } from '@/ui/layout/right-drawer/components/RightDrawerBody';
import { RightDrawerPage } from '@/ui/layout/right-drawer/components/RightDrawerPage';
import { RightDrawerTopBar } from '@/ui/layout/right-drawer/components/RightDrawerTopBar';
import { useGetCommentThreadsByTargetsQuery } from '~/generated/graphql';
import {
SortOrder,
useGetCommentThreadsByTargetsQuery,
} from '~/generated/graphql';
import { commentableEntityArrayState } from '../../states/commentableEntityArrayState';
@ -18,6 +21,11 @@ export function RightDrawerComments() {
commentThreadTargetIds: commentableEntityArray.map(
(commentableEntity) => commentableEntity.id,
),
orderBy: [
{
createdAt: SortOrder.Desc,
},
],
},
});