fix: debounce sidebar refresh on upload to avoid thousands of re-fetches
This commit is contained in:
parent
7386b215e2
commit
6c3ac6cb9c
@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useRef, useState } from 'react';
|
||||
import FileExplorer from './components/FileExplorer';
|
||||
import DocumentEditor from './components/DocumentEditor';
|
||||
import SearchBar from './components/SearchBar';
|
||||
@ -15,6 +15,12 @@ export default function App() {
|
||||
const [isDirty, setIsDirty] = useState(false);
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [uploadPath] = useState('');
|
||||
const refreshTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
function scheduleRefresh() {
|
||||
if (refreshTimer.current) clearTimeout(refreshTimer.current);
|
||||
refreshTimer.current = setTimeout(() => setRefreshKey((k) => k + 1), 400);
|
||||
}
|
||||
|
||||
function confirmDiscardIfDirty(): boolean {
|
||||
if (!isDirty) {
|
||||
@ -52,7 +58,7 @@ export default function App() {
|
||||
|
||||
function handleUploaded(result: UploadDocumentResponse) {
|
||||
setSelectedKey(result.key);
|
||||
setRefreshKey((prev) => prev + 1);
|
||||
scheduleRefresh();
|
||||
}
|
||||
|
||||
function handleDeleted() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user