cleanup
This commit is contained in:
@@ -22,7 +22,6 @@ interface UseDocumentsSearchArgs {
|
||||
documentsSortField?: string;
|
||||
documentsSortDirection?: string;
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
setLoading: (state: boolean) => void;
|
||||
setSearchIncludeDescendants: (value: boolean) => void;
|
||||
documentsManager: {
|
||||
ingest: (docs: unknown[]) => { canonical: DocumentLike[]; changed: boolean };
|
||||
@@ -75,7 +74,6 @@ const useDocumentsSearch = ({
|
||||
documentsSortField,
|
||||
documentsSortDirection,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
setSearchIncludeDescendants,
|
||||
documentsManager,
|
||||
}: UseDocumentsSearchArgs): UseDocumentsSearchResult => {
|
||||
@@ -193,7 +191,6 @@ const useDocumentsSearch = ({
|
||||
|
||||
const debounce = setTimeout(async () => {
|
||||
started = true;
|
||||
setLoading(true);
|
||||
try {
|
||||
const params: Record<string, unknown> = {};
|
||||
const trimmedQuery = searchQuery.trim();
|
||||
@@ -248,7 +245,6 @@ const useDocumentsSearch = ({
|
||||
setSearchResultIds(null);
|
||||
} finally {
|
||||
if (!cancelled && started) {
|
||||
setLoading(false);
|
||||
setSearchLoading(false);
|
||||
}
|
||||
}
|
||||
@@ -258,7 +254,6 @@ const useDocumentsSearch = ({
|
||||
cancelled = true;
|
||||
clearTimeout(debounce);
|
||||
if (started) {
|
||||
setLoading(false);
|
||||
setSearchLoading(false);
|
||||
}
|
||||
};
|
||||
@@ -274,7 +269,6 @@ const useDocumentsSearch = ({
|
||||
documentsSortDirection,
|
||||
selectedFolder,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
documentsManager,
|
||||
searchTrigger,
|
||||
]);
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
FolderOutlineIcon,
|
||||
TagIcon,
|
||||
CorrespondentIcon,
|
||||
LoaderIcon,
|
||||
} from '../ui/icons';
|
||||
import SelectionAssignmentMenu, { SelectionAssignmentMenuItem } from './SelectionAssignmentMenu';
|
||||
import SelectionSummary from './SelectionSummary';
|
||||
@@ -287,13 +286,11 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
|
||||
const tagLookupMap = tagLookupById instanceof Map ? tagLookupById : null;
|
||||
|
||||
const [remoteFolderOptions, setRemoteFolderOptions] = useState<SelectionAssignmentMenuItem[] | null>(null);
|
||||
const [loadingFolders, setLoadingFolders] = useState(false);
|
||||
const folderTreeFetchRef = useRef<Promise<SelectionAssignmentMenuItem[]> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setRemoteFolderOptions(null);
|
||||
folderTreeFetchRef.current = null;
|
||||
setLoadingFolders(false);
|
||||
}, [tenantId, token]);
|
||||
|
||||
const requestFolderTree = useCallback(async (): Promise<SelectionAssignmentMenuItem[]> => {
|
||||
@@ -311,7 +308,6 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
|
||||
}
|
||||
|
||||
const fetchPromise = (async () => {
|
||||
setLoadingFolders(true);
|
||||
try {
|
||||
const data = await getFolderTree();
|
||||
const options = buildFolderTreeOptions(data);
|
||||
@@ -322,7 +318,6 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
|
||||
setRemoteFolderOptions([]);
|
||||
return [];
|
||||
} finally {
|
||||
setLoadingFolders(false);
|
||||
folderTreeFetchRef.current = null;
|
||||
}
|
||||
})();
|
||||
@@ -521,19 +516,15 @@ const SelectionFloatingActions: React.FC<SelectionFloatingActionsProps> = ({
|
||||
label="Move"
|
||||
triggerContent={(
|
||||
<span className="quick-add__chip-label" title="Move">
|
||||
{loadingFolders ? (
|
||||
<LoaderIcon className="icon-inline icon--spin" aria-hidden="true" />
|
||||
) : (
|
||||
<FolderOutlineIcon className="icon-inline" aria-hidden="true" />
|
||||
)}
|
||||
<FolderOutlineIcon className="icon-inline" aria-hidden="true" />
|
||||
<span className="quick-add__chip-text" aria-hidden="true">Move</span>
|
||||
</span>
|
||||
)}
|
||||
items={moveAssignments}
|
||||
placeholder="Search folders…"
|
||||
emptyMessage={loadingFolders ? 'Loading folders…' : 'No folders'}
|
||||
emptyMessage="No folders"
|
||||
onToggle={(item) => handleMoveSelectionToFolder(item?.payload || item)}
|
||||
disabled={!documentCount || (loadingFolders && !moveAssignments.length)}
|
||||
disabled={!documentCount}
|
||||
createLabel={null}
|
||||
showStateIndicators={false}
|
||||
showCounts={false}
|
||||
|
||||
@@ -19,10 +19,9 @@ interface UseBulkDocumentActionsArgs {
|
||||
setStatusMessage: (message: string, variant?: string) => void;
|
||||
selectedDocumentIds?: Identifier[];
|
||||
selectedFolderIds?: Identifier[];
|
||||
handleDocumentsDelete: (ids: Identifier[], options?: { showMessage?: boolean; manageLoading?: boolean }) => Promise<boolean>;
|
||||
handleFolderDelete: (id: Identifier, options?: { showMessage?: boolean; manageLoading?: boolean }) => Promise<boolean>;
|
||||
handleDocumentsDelete: (ids: Identifier[], options?: { showMessage?: boolean }) => Promise<boolean>;
|
||||
handleFolderDelete: (id: Identifier, options?: { showMessage?: boolean }) => Promise<boolean>;
|
||||
clearDocumentSelection: () => void;
|
||||
setLoading: (value: boolean) => void;
|
||||
updateDocumentCaches?: (id: Identifier, updater: (doc: any) => any) => void;
|
||||
}
|
||||
|
||||
@@ -36,7 +35,6 @@ const useBulkDocumentActions = ({
|
||||
handleDocumentsDelete,
|
||||
handleFolderDelete,
|
||||
clearDocumentSelection,
|
||||
setLoading,
|
||||
updateDocumentCaches,
|
||||
}: UseBulkDocumentActionsArgs) => {
|
||||
const handleBulkCorrespondentAdd = useCallback(
|
||||
@@ -202,25 +200,20 @@ const useBulkDocumentActions = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
let docsOk = true;
|
||||
let foldersOk = true;
|
||||
|
||||
try {
|
||||
if (docIds.length) {
|
||||
docsOk = await handleDocumentsDelete(docIds, { showMessage: false, manageLoading: false });
|
||||
}
|
||||
if (docIds.length) {
|
||||
docsOk = await handleDocumentsDelete(docIds, { showMessage: false });
|
||||
}
|
||||
|
||||
if (folderIds.length) {
|
||||
for (const folderId of folderIds) {
|
||||
const success = await handleFolderDelete(folderId, { showMessage: false, manageLoading: false });
|
||||
if (!success) {
|
||||
foldersOk = false;
|
||||
}
|
||||
if (folderIds.length) {
|
||||
for (const folderId of folderIds) {
|
||||
const success = await handleFolderDelete(folderId, { showMessage: false });
|
||||
if (!success) {
|
||||
foldersOk = false;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
if (!docsOk || !foldersOk) {
|
||||
@@ -245,7 +238,6 @@ const useBulkDocumentActions = ({
|
||||
handleFolderDelete,
|
||||
selectedDocumentIds,
|
||||
selectedFolderIds,
|
||||
setLoading,
|
||||
setStatusMessage,
|
||||
]);
|
||||
|
||||
|
||||
@@ -8,14 +8,11 @@ type AppDispatch = (action: { type: string; [key: string]: unknown }) => void;
|
||||
|
||||
type SetStatusMessage = (message: string, variant?: string) => void;
|
||||
|
||||
type SetLoading = (state: boolean) => void;
|
||||
|
||||
interface UseAuthManagerArgs {
|
||||
token?: string | null;
|
||||
appStatus: AppStatus;
|
||||
appDispatch: AppDispatch;
|
||||
setStatusMessage: SetStatusMessage;
|
||||
setLoading: SetLoading;
|
||||
}
|
||||
|
||||
interface UseAuthManagerResult {
|
||||
@@ -29,7 +26,6 @@ const useAuthManager = ({
|
||||
appStatus,
|
||||
appDispatch,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
}: UseAuthManagerArgs): UseAuthManagerResult => {
|
||||
const tokenRef = useRef<string | null>(token);
|
||||
const initialRefreshAttemptedRef = useRef(Boolean(token));
|
||||
@@ -71,17 +67,15 @@ const useAuthManager = ({
|
||||
|
||||
const handleLogout = useCallback(async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
await logoutSession();
|
||||
} catch (error) {
|
||||
console.warn('[Auth] Failed to revoke refresh token during logout', error);
|
||||
} finally {
|
||||
clearAuthToken();
|
||||
setLoading(false);
|
||||
appDispatch({ type: 'LOGOUT' });
|
||||
setStatusMessage('Logged out.', 'info');
|
||||
}
|
||||
}, [appDispatch, setLoading, setStatusMessage]);
|
||||
}, [appDispatch, setStatusMessage]);
|
||||
|
||||
return { tokenRef, refreshAccessToken, handleLogout };
|
||||
};
|
||||
|
||||
@@ -90,7 +90,6 @@ interface DocumentTagExtras {
|
||||
|
||||
interface DeleteOptions {
|
||||
showMessage?: boolean;
|
||||
manageLoading?: boolean;
|
||||
}
|
||||
|
||||
interface TagAttachArgs {
|
||||
@@ -106,7 +105,6 @@ interface TagRemoveOptions {
|
||||
|
||||
interface FolderDeleteOptions {
|
||||
showMessage?: boolean;
|
||||
manageLoading?: boolean;
|
||||
}
|
||||
|
||||
interface UseDocumentMutationsArgs {
|
||||
@@ -129,7 +127,6 @@ interface UseDocumentMutationsArgs {
|
||||
focusedRowKey: string | null;
|
||||
notifyApiError: NotifyApiError;
|
||||
setStatusMessage: SetStatusMessage;
|
||||
setLoading: (next: boolean) => void;
|
||||
mapDocumentCaches: MapDocumentCaches;
|
||||
applySelectedFolder: ApplySelectedFolder;
|
||||
folderNodes: Map<FolderId, FolderNode>;
|
||||
@@ -204,7 +201,6 @@ const useDocumentMutations = ({
|
||||
focusedRowKey,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
mapDocumentCaches,
|
||||
applySelectedFolder,
|
||||
folderNodes,
|
||||
@@ -285,8 +281,6 @@ const useDocumentMutations = ({
|
||||
const id = getRowId(key);
|
||||
return id ? !uniqueIdSet.has(id as DocumentId) : true;
|
||||
});
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
if (uniqueIds.length === 1) {
|
||||
await moveDocumentToFolder(uniqueIds[0], target);
|
||||
@@ -377,8 +371,6 @@ const useDocumentMutations = ({
|
||||
} catch (error) {
|
||||
const message = (error as Record<string, any>)?.response?.data?.error || 'Failed to move documents.';
|
||||
notifyApiError(error, message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -399,7 +391,6 @@ const useDocumentMutations = ({
|
||||
focusedRowKey,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
mapDocumentCaches,
|
||||
],
|
||||
);
|
||||
@@ -410,7 +401,6 @@ const useDocumentMutations = ({
|
||||
setStatusMessage('Log in to manage assets.', 'error');
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
await queueDocumentReanalysis(documentId, { force: true });
|
||||
setStatusMessage('Document re-analysis queued.', 'info');
|
||||
@@ -418,15 +408,13 @@ const useDocumentMutations = ({
|
||||
} catch (error) {
|
||||
const message = (error as Record<string, any>)?.response?.data?.error || 'Failed to request thumbnail generation.';
|
||||
notifyApiError(error, message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[token, refreshCurrentFolder, notifyApiError, setStatusMessage, setLoading],
|
||||
[token, refreshCurrentFolder, notifyApiError, setStatusMessage],
|
||||
);
|
||||
|
||||
const handleDocumentsDelete = useCallback(
|
||||
async (documentIds: DocumentId[], { showMessage = true, manageLoading = true }: DeleteOptions = {}) => {
|
||||
async (documentIds: DocumentId[], { showMessage = true }: DeleteOptions = {}) => {
|
||||
if (!documentIds || documentIds.length === 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -436,10 +424,6 @@ const useDocumentMutations = ({
|
||||
return false;
|
||||
}
|
||||
|
||||
if (manageLoading) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(documentIds.map((documentId) => trashDocument(documentId)));
|
||||
|
||||
@@ -458,10 +442,6 @@ const useDocumentMutations = ({
|
||||
const message = (error as Record<string, any>)?.response?.data?.error || 'Failed to delete documents.';
|
||||
notifyApiError(error, message);
|
||||
return false;
|
||||
} finally {
|
||||
if (manageLoading) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -471,7 +451,6 @@ const useDocumentMutations = ({
|
||||
closeDocumentPreview,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -482,8 +461,6 @@ const useDocumentMutations = ({
|
||||
setStatusMessage('Document title cannot be empty.', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await updateDocument(documentId, { title: trimmed });
|
||||
const updatedDocument = extractDocumentFromResponse?.(data);
|
||||
@@ -505,24 +482,19 @@ const useDocumentMutations = ({
|
||||
const message = (error as Record<string, any>)?.response?.data?.error || 'Failed to update document title.';
|
||||
notifyApiError(error, message);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
extractDocumentFromResponse,
|
||||
ingestDocuments,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
setStatusMessage,
|
||||
updateDocumentCaches,
|
||||
],
|
||||
);
|
||||
|
||||
const handleDocumentIssuedUpdate = useCallback(
|
||||
async (documentId: DocumentId, nextIssuedDate: number | null) => {
|
||||
setLoading(true);
|
||||
const payload = { issued_at: nextIssuedDate || null };
|
||||
async (documentId: DocumentId, nextIssuedDate: number | null) => {const payload = { issued_at: nextIssuedDate || null };
|
||||
try {
|
||||
const data = await updateDocument(documentId, payload);
|
||||
const updatedDocument = extractDocumentFromResponse?.(data);
|
||||
@@ -545,15 +517,12 @@ const useDocumentMutations = ({
|
||||
const message = (error as Record<string, any>)?.response?.data?.error || 'Failed to update issued date.';
|
||||
notifyApiError(error, message);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
extractDocumentFromResponse,
|
||||
ingestDocuments,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
setStatusMessage,
|
||||
updateDocumentCaches,
|
||||
],
|
||||
@@ -719,7 +688,7 @@ const useDocumentMutations = ({
|
||||
);
|
||||
|
||||
const handleFolderDelete = useCallback(
|
||||
async (folderId?: FolderId, { showMessage = true, manageLoading = true }: FolderDeleteOptions = {}) => {
|
||||
async (folderId?: FolderId, { showMessage = true }: FolderDeleteOptions = {}) => {
|
||||
if (!token) {
|
||||
if (showMessage) {
|
||||
setStatusMessage('Log in to manage folders.', 'error');
|
||||
@@ -733,10 +702,6 @@ const useDocumentMutations = ({
|
||||
return false;
|
||||
}
|
||||
|
||||
if (manageLoading) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = await ensureFolderData(folderId, {
|
||||
force: true,
|
||||
@@ -802,10 +767,6 @@ const useDocumentMutations = ({
|
||||
setStatusMessage(message, 'error');
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
if (manageLoading) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -819,7 +780,6 @@ const useDocumentMutations = ({
|
||||
setFolderContents,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ interface UseDocumentTaggingArgs {
|
||||
resolveTargetDocumentIds: (ids?: Identifier[] | null) => Identifier[];
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
setStatusMessage: (message: string, variant?: string) => void;
|
||||
setLoading: (state: boolean) => void;
|
||||
updateDocumentCaches?: (id: Identifier, updater: (doc: TagRecord | null) => TagRecord | null) => void;
|
||||
}
|
||||
|
||||
@@ -50,7 +49,6 @@ const useDocumentTagging = ({
|
||||
resolveTargetDocumentIds,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
updateDocumentCaches,
|
||||
}: UseDocumentTaggingArgs) => {
|
||||
const bulkTagOperation = useCallback(
|
||||
@@ -80,7 +78,6 @@ const useDocumentTagging = ({
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
if (action === 'add') {
|
||||
const createdIds: Identifier[] = [];
|
||||
@@ -175,8 +172,6 @@ const useDocumentTagging = ({
|
||||
(action === 'add' ? 'Failed to assign tags.' : 'Failed to remove tags.');
|
||||
notifyApiError(error, message);
|
||||
return { ok: false, reason: 'request-failed' };
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -184,7 +179,6 @@ const useDocumentTagging = ({
|
||||
tags,
|
||||
refreshTags,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
tagManager,
|
||||
apiClient,
|
||||
updateDocumentCaches,
|
||||
@@ -265,7 +259,6 @@ const useDocumentTagging = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await apiClient.post<{ queued?: number }>(
|
||||
'/documents/bulk/reanalyze',
|
||||
@@ -286,11 +279,9 @@ const useDocumentTagging = ({
|
||||
const message =
|
||||
error.response?.data?.error || 'Failed to queue document re-analysis.';
|
||||
notifyApiError(error, message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[resolveTargetDocumentIds, notifyApiError, setStatusMessage, setLoading, apiClient],
|
||||
[resolveTargetDocumentIds, notifyApiError, setStatusMessage, apiClient],
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -102,7 +102,6 @@ interface UseDocumentUploadsArgs {
|
||||
currentFolderName?: string | null;
|
||||
ensureFolderData: (folderId: FolderId, options?: { force?: boolean; prefetchDepth?: number }) => Promise<void>;
|
||||
refreshCurrentFolder: () => Promise<void>;
|
||||
setLoading: (state: boolean) => void;
|
||||
shellRef: MutableRefObject<HTMLElement | null>;
|
||||
notifyApiError?: NotifyApiError;
|
||||
setStatusMessage?: SetStatusMessage;
|
||||
@@ -133,7 +132,6 @@ const useDocumentUploads = ({
|
||||
currentFolderName,
|
||||
ensureFolderData,
|
||||
refreshCurrentFolder,
|
||||
setLoading,
|
||||
shellRef,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
@@ -395,8 +393,6 @@ const useDocumentUploads = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
folderPathCacheRef.current.clear();
|
||||
|
||||
@@ -472,8 +468,6 @@ const useDocumentUploads = ({
|
||||
Object.assign(item, patch);
|
||||
});
|
||||
console.error('[Uploads] batch failed', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -483,7 +477,6 @@ const useDocumentUploads = ({
|
||||
refreshCurrentFolder,
|
||||
selectedFolder,
|
||||
ensureFolderData,
|
||||
setLoading,
|
||||
appendQueueItems,
|
||||
updateQueueItem,
|
||||
],
|
||||
|
||||
@@ -179,14 +179,12 @@ const useDocumentsWorkspace = ({
|
||||
reportApiError(error, { message: fallbackMessage, variant }),
|
||||
[reportApiError],
|
||||
);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [creatingFolder, setCreatingFolder] = useState(false);
|
||||
const { tokenRef, handleLogout } = useAuthManager({
|
||||
token,
|
||||
appStatus,
|
||||
appDispatch,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
});
|
||||
|
||||
const breadcrumbFetchRef = useRef(new Set());
|
||||
@@ -384,7 +382,6 @@ const useDocumentsWorkspace = ({
|
||||
documentsSortField,
|
||||
documentsSortDirection,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
setSearchIncludeDescendants,
|
||||
documentsManager,
|
||||
});
|
||||
@@ -590,19 +587,12 @@ const useDocumentsWorkspace = ({
|
||||
);
|
||||
|
||||
const refreshCurrentFolder = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const contents = await ensureFolderData(selectedFolder, {
|
||||
force: true,
|
||||
prefetchDepth: 1,
|
||||
});
|
||||
applySelectedFolder(selectedFolder, contents);
|
||||
} catch (error) {
|
||||
notifyApiError(error, 'Failed to refresh folder.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [selectedFolder, ensureFolderData, applySelectedFolder, notifyApiError]);
|
||||
const contents = await ensureFolderData(selectedFolder, {
|
||||
force: true,
|
||||
prefetchDepth: 1,
|
||||
});
|
||||
applySelectedFolder(selectedFolder, contents);
|
||||
}, [selectedFolder, ensureFolderData, applySelectedFolder]);
|
||||
|
||||
const {
|
||||
handleBulkTagAddFromDetail,
|
||||
@@ -616,7 +606,6 @@ const useDocumentsWorkspace = ({
|
||||
resolveTargetDocumentIds,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
updateDocumentCaches,
|
||||
});
|
||||
|
||||
@@ -636,7 +625,6 @@ const useDocumentsWorkspace = ({
|
||||
refreshCurrentFolder,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
shellRef,
|
||||
});
|
||||
|
||||
@@ -838,7 +826,6 @@ const useDocumentsWorkspace = ({
|
||||
focusedRowKey,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
mapDocumentCaches,
|
||||
applySelectedFolder,
|
||||
folderNodes,
|
||||
@@ -875,7 +862,6 @@ const useDocumentsWorkspace = ({
|
||||
applySelectedFolder,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
setFolderContents,
|
||||
setCurrentFolder,
|
||||
setSearchResultIds,
|
||||
@@ -914,18 +900,10 @@ const useDocumentsWorkspace = ({
|
||||
isFolderRowKey,
|
||||
});
|
||||
const initializeAfterLogin = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await Promise.all([refreshTags(), refreshCorrespondents()]);
|
||||
const initialFolder = routeFolderId && routeFolderId !== 'root' ? routeFolderId : 'root';
|
||||
await loadFolder(initialFolder, { showLoading: false });
|
||||
} catch (error) {
|
||||
notifyApiError(error, 'Failed to initialize data.');
|
||||
throw error;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [refreshTags, refreshCorrespondents, routeFolderId, loadFolder, notifyApiError]);
|
||||
await Promise.all([refreshTags(), refreshCorrespondents()]);
|
||||
const initialFolder = routeFolderId && routeFolderId !== 'root' ? routeFolderId : 'root';
|
||||
await loadFolder(initialFolder, {} );
|
||||
}, [refreshTags, refreshCorrespondents, routeFolderId, loadFolder]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
@@ -1007,7 +985,6 @@ const useDocumentsWorkspace = ({
|
||||
handleDocumentsDelete,
|
||||
handleFolderDelete,
|
||||
clearDocumentSelection,
|
||||
setLoading,
|
||||
updateDocumentCaches,
|
||||
});
|
||||
|
||||
@@ -1380,7 +1357,6 @@ const useDocumentsWorkspace = ({
|
||||
resetWorkspaceState,
|
||||
setStatusMessage,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
refreshTags,
|
||||
refreshCorrespondents,
|
||||
loadFolder,
|
||||
@@ -1552,7 +1528,6 @@ const useDocumentsWorkspace = ({
|
||||
correspondents,
|
||||
handleCorrespondentCreate,
|
||||
appStatus,
|
||||
loading,
|
||||
previewActive,
|
||||
handleLogout,
|
||||
status,
|
||||
|
||||
@@ -35,7 +35,6 @@ interface EnsureFolderOptions {
|
||||
}
|
||||
|
||||
interface LoadFolderOptions {
|
||||
showLoading?: boolean;
|
||||
preserveSearch?: boolean;
|
||||
}
|
||||
|
||||
@@ -64,7 +63,6 @@ interface UseFolderTreeActionsOptions {
|
||||
applySelectedFolder: (folderId: FolderKey, contents: any) => void;
|
||||
notifyApiError: (error: unknown, message?: string) => void;
|
||||
setStatusMessage: (message: string, level?: string) => void;
|
||||
setLoading: (value: boolean) => void;
|
||||
setFolderContents: (
|
||||
updater: (prev: Map<FolderKey, FolderContentsState>) => Map<FolderKey, FolderContentsState>,
|
||||
) => void;
|
||||
@@ -94,7 +92,6 @@ const useFolderTreeActions = ({
|
||||
applySelectedFolder,
|
||||
notifyApiError,
|
||||
setStatusMessage,
|
||||
setLoading,
|
||||
setFolderContents,
|
||||
setCurrentFolder,
|
||||
setSearchResultIds,
|
||||
@@ -211,12 +208,11 @@ const useFolderTreeActions = ({
|
||||
);
|
||||
|
||||
const loadFolder = useCallback(
|
||||
async (folderId: FolderKey | null, { showLoading = true, preserveSearch = false }: LoadFolderOptions = {}) => {
|
||||
async (folderId: FolderKey | null, { preserveSearch = false }: LoadFolderOptions = {}) => {
|
||||
const targetId = folderId || 'root';
|
||||
setSelectedFolder(targetId);
|
||||
await ensureFolderAncestorsLoaded(targetId);
|
||||
expandFolderAncestors(targetId);
|
||||
if (showLoading) setLoading(true);
|
||||
try {
|
||||
const contents = await ensureFolderData(targetId, { force: true, prefetchDepth: 1 });
|
||||
if (targetId !== 'root') {
|
||||
@@ -236,8 +232,6 @@ const useFolderTreeActions = ({
|
||||
}
|
||||
} catch (error) {
|
||||
notifyApiError(error, 'Failed to load folder contents.');
|
||||
} finally {
|
||||
if (showLoading) setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -246,7 +240,6 @@ const useFolderTreeActions = ({
|
||||
ensureFolderData,
|
||||
expandFolderAncestors,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
setSearchResultIds,
|
||||
setSelectedFolder,
|
||||
],
|
||||
@@ -289,8 +282,6 @@ const useFolderTreeActions = ({
|
||||
setStatusMessage('Folder name cannot be empty.', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
await renameFolderRequest(folderId, trimmed);
|
||||
|
||||
@@ -323,8 +314,6 @@ const useFolderTreeActions = ({
|
||||
const message = error.response?.data?.error || 'Failed to rename folder.';
|
||||
notifyApiError(error, message);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -332,7 +321,6 @@ const useFolderTreeActions = ({
|
||||
setCurrentFolder,
|
||||
setFolderContents,
|
||||
setFolderNodes,
|
||||
setLoading,
|
||||
setStatusMessage,
|
||||
token,
|
||||
],
|
||||
@@ -412,7 +400,7 @@ const useFolderTreeActions = ({
|
||||
);
|
||||
|
||||
const handleFolderDelete = useCallback(
|
||||
async (folderId: FolderKey, { showMessage = true, manageLoading = true }: { showMessage?: boolean; manageLoading?: boolean } = {}) => {
|
||||
async (folderId: FolderKey, { showMessage = true }: { showMessage?: boolean } = {}) => {
|
||||
if (!token) {
|
||||
if (showMessage) {
|
||||
setStatusMessage('Log in to manage folders.', 'error');
|
||||
@@ -426,10 +414,6 @@ const useFolderTreeActions = ({
|
||||
return false;
|
||||
}
|
||||
|
||||
if (manageLoading) {
|
||||
setLoading(true);
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = await ensureFolderData(folderId, {
|
||||
force: true,
|
||||
@@ -495,10 +479,6 @@ const useFolderTreeActions = ({
|
||||
setStatusMessage(message, 'error');
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
if (manageLoading) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -510,7 +490,6 @@ const useFolderTreeActions = ({
|
||||
selectedFolder,
|
||||
setFolderContents,
|
||||
setFolderNodes,
|
||||
setLoading,
|
||||
setSelectedFolder,
|
||||
setStatusMessage,
|
||||
],
|
||||
|
||||
@@ -19,10 +19,9 @@ interface UseTenantManagerOptions {
|
||||
resetWorkspaceState: () => void;
|
||||
setStatusMessage: (message: string, variant?: string) => void;
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
setLoading: (state: boolean) => void;
|
||||
refreshTags: () => Promise<void>;
|
||||
refreshCorrespondents: () => Promise<void>;
|
||||
loadFolder: (folderId: string, options?: { showLoading?: boolean; preserveSearch?: boolean }) => Promise<void>;
|
||||
loadFolder: (folderId: string, options?: { preserveSearch?: boolean }) => Promise<void>;
|
||||
handleDocumentsViewModeChange: (mode: string) => void;
|
||||
navigate: NavigateFunction;
|
||||
tokenRef?: MutableRefObject<string | null>;
|
||||
@@ -36,7 +35,6 @@ const useTenantManager = ({
|
||||
resetWorkspaceState,
|
||||
setStatusMessage,
|
||||
notifyApiError,
|
||||
setLoading,
|
||||
refreshTags,
|
||||
refreshCorrespondents,
|
||||
loadFolder,
|
||||
@@ -52,7 +50,6 @@ const useTenantManager = ({
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
if (!refreshOnly) {
|
||||
setStatusMessage('Switching tenant…', 'info');
|
||||
@@ -99,14 +96,12 @@ const useTenantManager = ({
|
||||
navigate('/documents', { replace: true });
|
||||
|
||||
await Promise.all([refreshTags(), refreshCorrespondents()]);
|
||||
await loadFolder('root', { showLoading: false, preserveSearch: false });
|
||||
await loadFolder('root', { preserveSearch: false });
|
||||
|
||||
const tenantLabel = data?.tenant?.name || data?.tenant?.id || 'tenant';
|
||||
setStatusMessage(`Switched to ${tenantLabel}.`, 'info');
|
||||
} catch (error) {
|
||||
notifyApiError(error, 'Failed to switch tenant.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[
|
||||
@@ -120,7 +115,6 @@ const useTenantManager = ({
|
||||
refreshCorrespondents,
|
||||
refreshTags,
|
||||
resetWorkspaceState,
|
||||
setLoading,
|
||||
setStatusMessage,
|
||||
tenantIdRef,
|
||||
tokenRef,
|
||||
|
||||
@@ -40,7 +40,7 @@ interface UseApiTokensResult {
|
||||
|
||||
const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensArgs): UseApiTokensResult => {
|
||||
const [tokens, setTokens] = useState<ApiTokenRecord[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [loading] = useState(false);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [deletingId, setDeletingId] = useState<string | number | null>(null);
|
||||
const [regeneratingId, setRegeneratingId] = useState<string | number | null>(null);
|
||||
@@ -50,14 +50,11 @@ const useApiTokens = ({ notifyApiError, setStatusMessage, token }: UseApiTokensA
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await listApiTokens();
|
||||
setTokens(Array.isArray(data) ? data : []);
|
||||
} catch (error) {
|
||||
notifyApiError?.(error, 'Failed to load API tokens.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [notifyApiError, token]);
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ interface UseSidebarPropsArgs {
|
||||
| null
|
||||
| void;
|
||||
appStatus: string;
|
||||
loading: boolean;
|
||||
previewActive: boolean;
|
||||
handleLogout: () => void | Promise<void>;
|
||||
status: StatusMessage | null;
|
||||
@@ -122,7 +121,6 @@ interface SidebarHookResult {
|
||||
correspondents: CorrespondentOption[];
|
||||
onCreateCorrespondent: (name: string) => void;
|
||||
appStatus: string;
|
||||
loading: boolean;
|
||||
previewActive: boolean;
|
||||
onLogout: UseSidebarPropsArgs['handleLogout'];
|
||||
status: StatusMessage | null;
|
||||
@@ -151,7 +149,6 @@ const useSidebarProps = ({
|
||||
correspondents,
|
||||
handleCorrespondentCreate,
|
||||
appStatus,
|
||||
loading,
|
||||
previewActive,
|
||||
handleLogout,
|
||||
status,
|
||||
@@ -185,7 +182,6 @@ const useSidebarProps = ({
|
||||
correspondents,
|
||||
onCreateCorrespondent: (name) => handleCorrespondentCreate({ name }),
|
||||
appStatus,
|
||||
loading,
|
||||
previewActive,
|
||||
onLogout: handleLogout,
|
||||
status,
|
||||
@@ -228,7 +224,6 @@ const useSidebarProps = ({
|
||||
handlePromptCreateFolder,
|
||||
handleTagCreate,
|
||||
handleTenantSelect,
|
||||
loading,
|
||||
openSettings,
|
||||
previewActive,
|
||||
draggedFolderId,
|
||||
|
||||
Reference in New Issue
Block a user