@renegade-fi/react
Advanced tools
Comparing version 0.0.0-canary-20240525000847 to 0.0.0-canary-20240525002754
@@ -14,4 +14,10 @@ 'use client'; | ||
onUpdate: (incoming) => { | ||
console.log('🚀 ~ incoming:', incoming); | ||
setTaskHistory((prev) => new Map(prev).set(incoming.id, incoming)); | ||
setTaskHistory((prev) => { | ||
if (prev.get(incoming.id) !== incoming) { | ||
const newMap = new Map(prev); | ||
newMap.set(incoming.id, incoming); | ||
return newMap; | ||
} | ||
return prev; | ||
}); | ||
}, | ||
@@ -26,4 +32,3 @@ }); | ||
const initialTaskHistory = await getTaskHistory(config); | ||
const taskMap = new Map(initialTaskHistory.map((task) => [task.id, task])); | ||
setTaskHistory(taskMap); | ||
setTaskHistory(new Map(initialTaskHistory)); | ||
} | ||
@@ -30,0 +35,0 @@ fetchTaskHistory(); |
@@ -12,2 +12,3 @@ 'use client'; | ||
const status = useStatus(parameters); | ||
const queryClient = useQueryClient(); | ||
const options = getTaskHistoryQueryOptions(config, { | ||
@@ -17,10 +18,24 @@ ...parameters, | ||
const enabled = Boolean(status === 'in relayer' && (query.enabled ?? true)); | ||
const queryClient = useQueryClient(); | ||
console.log('🚀 ~ queryClient:', queryClient); | ||
useTaskHistoryWebSocket({ | ||
onUpdate: (incoming) => { | ||
console.log('🚀 ~ incoming:', incoming); | ||
// if (queryClient && options.queryKey) { | ||
// queryClient.setQueryData(options.queryKey, incoming) | ||
// } | ||
if (queryClient && options.queryKey) { | ||
const existingMap = queryClient.getQueryData(options.queryKey) || | ||
new Map(); | ||
const existingTask = existingMap.get(incoming.id); | ||
console.debug('onUpdate debug: ', { | ||
existingMap, | ||
existingTask, | ||
incoming, | ||
}); | ||
if (!existingTask || incoming.state !== existingTask.state) { | ||
console.debug('setting debug', { | ||
existingMap, | ||
existingTask, | ||
incoming, | ||
}); | ||
const newMap = new Map(existingMap); | ||
newMap.set(incoming.id, incoming); | ||
queryClient.setQueryData(options.queryKey, newMap); | ||
} | ||
} | ||
}, | ||
@@ -27,0 +42,0 @@ }); |
{ | ||
"name": "@renegade-fi/react", | ||
"version": "0.0.0-canary-20240525000847", | ||
"version": "0.0.0-canary-20240525002754", | ||
"description": "React library for Renegade", | ||
@@ -34,3 +34,3 @@ "files": [ | ||
"tiny-invariant": "^1.3.3", | ||
"@renegade-fi/core": "0.0.0-canary-20240525000847" | ||
"@renegade-fi/core": "0.0.0-canary-20240525002754" | ||
}, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
@@ -24,6 +24,13 @@ 'use client' | ||
const [taskHistory, setTaskHistory] = useState<Map<string, Task>>(new Map()) | ||
useTaskHistoryWebSocket({ | ||
onUpdate: (incoming: Task) => { | ||
console.log('🚀 ~ incoming:', incoming) | ||
setTaskHistory((prev) => new Map(prev).set(incoming.id, incoming)) | ||
setTaskHistory((prev) => { | ||
if (prev.get(incoming.id) !== incoming) { | ||
const newMap = new Map(prev) | ||
newMap.set(incoming.id, incoming) | ||
return newMap | ||
} | ||
return prev | ||
}) | ||
}, | ||
@@ -40,4 +47,3 @@ }) | ||
const initialTaskHistory = await getTaskHistory(config) | ||
const taskMap = new Map(initialTaskHistory.map((task) => [task.id, task])) | ||
setTaskHistory(taskMap) | ||
setTaskHistory(new Map(initialTaskHistory)) | ||
} | ||
@@ -44,0 +50,0 @@ |
@@ -42,2 +42,3 @@ 'use client' | ||
const status = useStatus(parameters) | ||
const queryClient = useQueryClient() | ||
@@ -49,15 +50,29 @@ const options = getTaskHistoryQueryOptions(config, { | ||
const queryClient = useQueryClient() | ||
console.log('🚀 ~ queryClient:', queryClient) | ||
useTaskHistoryWebSocket({ | ||
onUpdate: (incoming: Task) => { | ||
console.log('🚀 ~ incoming:', incoming) | ||
// if (queryClient && options.queryKey) { | ||
// queryClient.setQueryData(options.queryKey, incoming) | ||
// } | ||
if (queryClient && options.queryKey) { | ||
const existingMap = | ||
queryClient.getQueryData<GetTaskHistoryData>(options.queryKey) || | ||
new Map() | ||
const existingTask = existingMap.get(incoming.id) | ||
console.debug('onUpdate debug: ', { | ||
existingMap, | ||
existingTask, | ||
incoming, | ||
}) | ||
if (!existingTask || incoming.state !== existingTask.state) { | ||
console.debug('setting debug', { | ||
existingMap, | ||
existingTask, | ||
incoming, | ||
}) | ||
const newMap = new Map(existingMap) | ||
newMap.set(incoming.id, incoming) | ||
queryClient.setQueryData(options.queryKey, newMap) | ||
} | ||
} | ||
}, | ||
}) | ||
return useQuery({ ...query, ...options, enabled }) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
702957
3081
+ Added@renegade-fi/core@0.0.0-canary-20240525002754(transitive)
- Removed@renegade-fi/core@0.0.0-canary-20240525000847(transitive)