mirror of
https://github.com/coleam00/Archon.git
synced 2025-12-24 02:39:17 -05:00
fix: Correct ActiveOperationsResponse handling in useCrawlUrlV2
- Fixed missing count and timestamp fields in optimistic updates - Preserve all ActiveOperationsResponse fields when updating progress IDs - Fixed incorrect field comparison (source_id vs id) when replacing temp IDs - Added query invalidation for progress queries in v2 implementation - Ensures proper data shape consistency with backend API These fixes ensure that: 1. ActiveOperationsResponse always has required count/timestamp fields 2. Optimistic entities are correctly matched and updated with real IDs 3. Progress queries are properly refreshed after crawl starts
This commit is contained in:
@@ -401,6 +401,8 @@ export function useCrawlUrlV2() {
|
||||
progressId: tempProgressId,
|
||||
} as ActiveOperation,
|
||||
],
|
||||
count: 1,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
} else {
|
||||
queryClient.setQueryData<ActiveOperationsResponse>(progressKeys.active(), {
|
||||
@@ -416,6 +418,8 @@ export function useCrawlUrlV2() {
|
||||
} as ActiveOperation,
|
||||
...(previousOperations.operations || []),
|
||||
],
|
||||
count: (previousOperations.count || 0) + 1,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -429,7 +433,8 @@ export function useCrawlUrlV2() {
|
||||
if (context) {
|
||||
const activeOps = queryClient.getQueryData<ActiveOperationsResponse>(progressKeys.active());
|
||||
if (activeOps) {
|
||||
const updated = {
|
||||
const updated: ActiveOperationsResponse = {
|
||||
...activeOps, // Preserve count, timestamp, and any other fields
|
||||
operations: activeOps.operations.map((op) =>
|
||||
op.progressId === context.tempProgressId ? { ...op, progressId: response.progressId } : op,
|
||||
),
|
||||
@@ -446,7 +451,7 @@ export function useCrawlUrlV2() {
|
||||
const updated = {
|
||||
...data,
|
||||
items: data.items.map((item) =>
|
||||
item.id === context.tempItemId ? { ...item, source_id: response.progressId } : item,
|
||||
item.source_id === context.tempProgressId ? { ...item, source_id: response.progressId } : item,
|
||||
),
|
||||
};
|
||||
queryClient.setQueryData(qk, updated);
|
||||
@@ -454,6 +459,9 @@ export function useCrawlUrlV2() {
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate to get fresh data
|
||||
queryClient.invalidateQueries({ queryKey: progressKeys.active() });
|
||||
|
||||
// Return the response so caller can access progressId
|
||||
return response;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user