import { useMutation, useQueryClient } from "@tanstack/react-query"; import { cancelDreamTask } from "@/services/memory"; export function useCancelDreamTask(memoryStoreName: string) { const queryClient = useQueryClient(); return useMutation({ mutationFn: (dreamId: string) => cancelDreamTask(memoryStoreName, dreamId), onSuccess: () => { // The cancel response carries the new status, but the detail-page // hook already polls — invalidating both the list and detail keys // forces an immediate refresh in the listing too. queryClient.invalidateQueries({ queryKey: ["memory"], predicate: (q) => Array.isArray(q.queryKey) && q.queryKey.includes("dream-tasks") && q.queryKey.includes(memoryStoreName), }); }, }); }