import { useMutation, useQueryClient } from "@tanstack/react-query"; import { createDreamTask } from "@/services/memory"; import type { CreateDreamTaskRequest } from "@/types/memory"; export function useCreateDreamTask(memoryStoreName: string) { const queryClient = useQueryClient(); return useMutation({ mutationFn: (request: CreateDreamTaskRequest) => createDreamTask(memoryStoreName, request), onSuccess: () => { // Invalidate the list of dream tasks for this store so the new task // shows up immediately. The detail-page polling hook will pick up // the freshly-created task once the user navigates there. queryClient.invalidateQueries({ queryKey: ["memory"], predicate: (q) => Array.isArray(q.queryKey) && q.queryKey.includes("dream-tasks") && q.queryKey.includes(memoryStoreName), }); }, }); }