This commit is contained in:
2025-11-23 00:11:18 +01:00
parent 014f489857
commit 85afff2c19
12 changed files with 34 additions and 179 deletions
@@ -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,
],
);