Preventing document list reload from blocking dialogs to close faster
- Changed document refresh operations to execute asynchronously, no longer blocking UI response - Added proper error handling to ensure refresh failures don't affect user experience - Removed redundant health check calls as the document manager already includes state update logic
This commit is contained in:
@@ -14,7 +14,6 @@ import Checkbox from '@/components/ui/Checkbox'
|
|||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import { errorMessage } from '@/lib/utils'
|
import { errorMessage } from '@/lib/utils'
|
||||||
import { clearDocuments, clearCache } from '@/api/lightrag'
|
import { clearDocuments, clearCache } from '@/api/lightrag'
|
||||||
import { useBackendState } from '@/stores/state'
|
|
||||||
|
|
||||||
import { EraserIcon, AlertTriangleIcon } from 'lucide-react'
|
import { EraserIcon, AlertTriangleIcon } from 'lucide-react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -45,7 +44,6 @@ export default function ClearDocumentsDialog({ onDocumentsCleared }: ClearDocume
|
|||||||
const [confirmText, setConfirmText] = useState('')
|
const [confirmText, setConfirmText] = useState('')
|
||||||
const [clearCacheOption, setClearCacheOption] = useState(false)
|
const [clearCacheOption, setClearCacheOption] = useState(false)
|
||||||
const isConfirmEnabled = confirmText.toLowerCase() === 'yes'
|
const isConfirmEnabled = confirmText.toLowerCase() === 'yes'
|
||||||
const check = useBackendState.use.check()
|
|
||||||
|
|
||||||
// 重置状态当对话框关闭时
|
// 重置状态当对话框关闭时
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -78,12 +76,9 @@ export default function ClearDocumentsDialog({ onDocumentsCleared }: ClearDocume
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update health check status
|
|
||||||
await check()
|
|
||||||
|
|
||||||
// Refresh document list if provided
|
// Refresh document list if provided
|
||||||
if (onDocumentsCleared) {
|
if (onDocumentsCleared) {
|
||||||
await onDocumentsCleared()
|
onDocumentsCleared().catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 所有操作成功后关闭对话框
|
// 所有操作成功后关闭对话框
|
||||||
@@ -92,7 +87,7 @@ export default function ClearDocumentsDialog({ onDocumentsCleared }: ClearDocume
|
|||||||
toast.error(t('documentPanel.clearDocuments.error', { error: errorMessage(err) }))
|
toast.error(t('documentPanel.clearDocuments.error', { error: errorMessage(err) }))
|
||||||
setConfirmText('')
|
setConfirmText('')
|
||||||
}
|
}
|
||||||
}, [isConfirmEnabled, clearCacheOption, setOpen, t, check, onDocumentsCleared])
|
}, [isConfirmEnabled, clearCacheOption, setOpen, t, onDocumentsCleared])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { useState, useCallback } from 'react'
|
import { useState, useCallback } from 'react'
|
||||||
import { useBackendState } from '@/stores/state'
|
|
||||||
import { FileRejection } from 'react-dropzone'
|
import { FileRejection } from 'react-dropzone'
|
||||||
import Button from '@/components/ui/Button'
|
import Button from '@/components/ui/Button'
|
||||||
import {
|
import {
|
||||||
@@ -28,7 +27,6 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
|||||||
const [isUploading, setIsUploading] = useState(false)
|
const [isUploading, setIsUploading] = useState(false)
|
||||||
const [progresses, setProgresses] = useState<Record<string, number>>({})
|
const [progresses, setProgresses] = useState<Record<string, number>>({})
|
||||||
const [fileErrors, setFileErrors] = useState<Record<string, string>>({})
|
const [fileErrors, setFileErrors] = useState<Record<string, string>>({})
|
||||||
const check = useBackendState.use.check()
|
|
||||||
|
|
||||||
const handleRejectedFiles = useCallback(
|
const handleRejectedFiles = useCallback(
|
||||||
(rejectedFiles: FileRejection[]) => {
|
(rejectedFiles: FileRejection[]) => {
|
||||||
@@ -155,16 +153,11 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
|||||||
|
|
||||||
// Only update if at least one file was uploaded successfully
|
// Only update if at least one file was uploaded successfully
|
||||||
if (hasSuccessfulUpload) {
|
if (hasSuccessfulUpload) {
|
||||||
try {
|
// Refresh document list
|
||||||
// Update backend state
|
if (onDocumentsUploaded) {
|
||||||
await check()
|
onDocumentsUploaded().catch(err => {
|
||||||
|
console.error('Error refreshing documents:', err)
|
||||||
// Refresh document list
|
})
|
||||||
if (onDocumentsUploaded) {
|
|
||||||
await onDocumentsUploaded()
|
|
||||||
}
|
|
||||||
} catch (refreshErr) {
|
|
||||||
console.error('Error refreshing state:', refreshErr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -174,7 +167,7 @@ export default function UploadDocumentsDialog({ onDocumentsUploaded }: UploadDoc
|
|||||||
setIsUploading(false)
|
setIsUploading(false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[setIsUploading, setProgresses, setFileErrors, t, check, onDocumentsUploaded]
|
[setIsUploading, setProgresses, setFileErrors, t, onDocumentsUploaded]
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Reference in New Issue
Block a user