fix: invalidate comments query on comment reaction and delete (#5641)
This commit is contained in:
parent
122ac94273
commit
1d9d4cd797
2 changed files with 14 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ import { useCallback } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
import { useInstance } from "@/contexts/InstanceContext";
|
import { useInstance } from "@/contexts/InstanceContext";
|
||||||
import { useDeleteMemo, useUpdateMemo } from "@/hooks/useMemoQueries";
|
import { memoKeys, useDeleteMemo, useUpdateMemo } from "@/hooks/useMemoQueries";
|
||||||
import useNavigateTo from "@/hooks/useNavigateTo";
|
import useNavigateTo from "@/hooks/useNavigateTo";
|
||||||
import { userKeys } from "@/hooks/useUserQueries";
|
import { userKeys } from "@/hooks/useUserQueries";
|
||||||
import { handleError } from "@/lib/error";
|
import { handleError } from "@/lib/error";
|
||||||
|
|
@ -98,13 +98,20 @@ export const useMemoActionHandlers = ({ memo, onEdit, setDeleteDialogOpen }: Use
|
||||||
}, [setDeleteDialogOpen]);
|
}, [setDeleteDialogOpen]);
|
||||||
|
|
||||||
const confirmDeleteMemo = useCallback(async () => {
|
const confirmDeleteMemo = useCallback(async () => {
|
||||||
await deleteMemo(memo.name);
|
await deleteMemo(memo.name, {
|
||||||
|
onSuccess: () => {
|
||||||
|
// If this was a comment, refresh the parent memo's comments list so it disappears from the UI
|
||||||
|
if (memo.parent) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: memoKeys.comments(memo.parent) });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
toast.success(t("message.deleted-successfully"));
|
toast.success(t("message.deleted-successfully"));
|
||||||
if (isInMemoDetailPage) {
|
if (isInMemoDetailPage) {
|
||||||
navigateTo("/");
|
navigateTo("/");
|
||||||
}
|
}
|
||||||
memoUpdatedCallback();
|
memoUpdatedCallback();
|
||||||
}, [memo.name, t, isInMemoDetailPage, navigateTo, memoUpdatedCallback, deleteMemo]);
|
}, [memo.name, memo.parent, t, isInMemoDetailPage, navigateTo, memoUpdatedCallback, deleteMemo, queryClient]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleTogglePinMemoBtnClick,
|
handleTogglePinMemoBtnClick,
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ export const useReactionActions = ({ memo, onComplete }: UseReactionActionsOptio
|
||||||
const updatedMemo = await memoServiceClient.getMemo({ name: memo.name });
|
const updatedMemo = await memoServiceClient.getMemo({ name: memo.name });
|
||||||
queryClient.setQueryData(memoKeys.detail(memo.name), updatedMemo);
|
queryClient.setQueryData(memoKeys.detail(memo.name), updatedMemo);
|
||||||
queryClient.invalidateQueries({ queryKey: memoKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: memoKeys.lists() });
|
||||||
|
// If this memo is a comment, refresh the parent's comments list so the comment's reactions update in the UI
|
||||||
|
if (memo.parent) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: memoKeys.comments(memo.parent) });
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// skip error
|
// skip error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue