fix: resolve quick refresh after clearing documents in DocumentManager
- Fix handleDocumentsCleared to use proper 30s idle interval instead of 500ms - Update smart polling useEffect to depend on complete statusCounts object - Reset status counts immediately when documents are cleared
This commit is contained in:
parent
5e2b262094
commit
47002e645b
1 changed files with 29 additions and 5 deletions
|
|
@ -651,7 +651,7 @@ export default function DocumentManager() {
|
||||||
return () => {
|
return () => {
|
||||||
clearPollingInterval();
|
clearPollingInterval();
|
||||||
}
|
}
|
||||||
}, [health, t, currentTab, statusCounts.processing, statusCounts.pending, startPollingInterval, clearPollingInterval])
|
}, [health, t, currentTab, statusCounts, startPollingInterval, clearPollingInterval])
|
||||||
|
|
||||||
// Monitor docs changes to check status counts and trigger health check if needed
|
// Monitor docs changes to check status counts and trigger health check if needed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -714,11 +714,35 @@ export default function DocumentManager() {
|
||||||
startPollingInterval(2000)
|
startPollingInterval(2000)
|
||||||
}, [startPollingInterval])
|
}, [startPollingInterval])
|
||||||
|
|
||||||
// Handle documents cleared callback with delayed health check timer reset
|
// Handle documents cleared callback with proper interval reset
|
||||||
const handleDocumentsCleared = useCallback(async () => {
|
const handleDocumentsCleared = useCallback(async () => {
|
||||||
// Schedule a health check 0.5 seconds after successful clear
|
// Clear current polling interval
|
||||||
startPollingInterval(500)
|
clearPollingInterval();
|
||||||
}, [startPollingInterval])
|
|
||||||
|
// Reset status counts to ensure proper state
|
||||||
|
setStatusCounts({
|
||||||
|
all: 0,
|
||||||
|
processed: 0,
|
||||||
|
processing: 0,
|
||||||
|
pending: 0,
|
||||||
|
failed: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// Perform one immediate refresh to confirm clear operation
|
||||||
|
if (isMountedRef.current) {
|
||||||
|
try {
|
||||||
|
await fetchDocuments();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching documents after clear:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set appropriate polling interval based on current state
|
||||||
|
// Since documents are cleared, use idle interval (30 seconds)
|
||||||
|
if (currentTab === 'documents' && health && isMountedRef.current) {
|
||||||
|
startPollingInterval(30000); // 30 seconds for idle state
|
||||||
|
}
|
||||||
|
}, [clearPollingInterval, setStatusCounts, fetchDocuments, currentTab, health, startPollingInterval])
|
||||||
|
|
||||||
|
|
||||||
// Handle showFileName change - switch sort field if currently sorting by first column
|
// Handle showFileName change - switch sort field if currently sorting by first column
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue