|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import { |
4 | | - InfiniteData, |
5 | | - useMutation, |
6 | | - useQueryClient, |
7 | | -} from '@tanstack/react-query'; |
| 3 | +import { useMutation, useQueryClient } from '@tanstack/react-query'; |
8 | 4 | import { agentRPCNonStreaming } from 'agentex/lib'; |
9 | 5 |
|
10 | 6 | import { toast } from '@/components/agentex/toast'; |
11 | 7 |
|
12 | 8 | import { tasksKeys } from './use-tasks'; |
13 | 9 |
|
14 | 10 | import type AgentexSDK from 'agentex'; |
15 | | -import type { Task, TaskListResponse } from 'agentex/resources'; |
| 11 | +import type { Task } from 'agentex/resources'; |
16 | 12 |
|
17 | 13 | type CreateTaskParams = { |
18 | 14 | agentName: string; |
@@ -49,40 +45,11 @@ export function useCreateTask({ |
49 | 45 |
|
50 | 46 | return response.result; |
51 | 47 | }, |
52 | | - onSuccess: (newTask, variables) => { |
53 | | - // Helper function to update infinite query cache |
54 | | - const updateInfiniteCache = (queryKey: readonly unknown[]) => { |
55 | | - queryClient.setQueryData<InfiniteData<TaskListResponse>>( |
56 | | - queryKey, |
57 | | - old => { |
58 | | - if (!old || !old.pages || old.pages.length === 0) { |
59 | | - // If no cache exists, create initial structure |
60 | | - return { |
61 | | - pages: [[newTask]], |
62 | | - pageParams: [1], |
63 | | - }; |
64 | | - } |
65 | | - |
66 | | - // Add new task to the first page (prepend to show at top) |
67 | | - const firstPage = old.pages[0] ?? []; |
68 | | - if (firstPage.some(t => t.id === newTask.id)) { |
69 | | - return old; // Avoid duplicates |
70 | | - } |
71 | | - |
72 | | - return { |
73 | | - ...old, |
74 | | - pages: [[newTask, ...firstPage], ...old.pages.slice(1)], |
75 | | - }; |
76 | | - } |
77 | | - ); |
78 | | - }; |
79 | | - |
80 | | - // Update both the agent-specific cache and the generic "all tasks" cache |
81 | | - updateInfiniteCache(tasksKeys.byAgentName(variables.agentName)); |
82 | | - updateInfiniteCache(tasksKeys.all); |
83 | | - |
84 | | - // Invalidate all task queries to ensure consistency |
| 48 | + onSuccess: (_, variables) => { |
85 | 49 | queryClient.invalidateQueries({ queryKey: tasksKeys.all }); |
| 50 | + queryClient.invalidateQueries({ |
| 51 | + queryKey: tasksKeys.byAgentName(variables.agentName), |
| 52 | + }); |
86 | 53 | }, |
87 | 54 | onError: error => { |
88 | 55 | toast.error({ |
|
0 commit comments