feat: enhance frontend tag operations with UI notifications.

This commit is contained in:
2025-12-10 00:01:33 +01:00
parent 1d8d55144f
commit 82dcd6d33c
4 changed files with 89 additions and 90 deletions
@@ -8,6 +8,9 @@ import type { Identifier } from '../../types/identifiers';
import type { Document } from '../../types/documents';
import { resolveBreadcrumbs } from '../../documents/logic/breadcrumbs';
import type { Tag, Correspondent } from '../../types/documents';
import { listFolderContents } from '../../lib/api/apiClient';
import { useStatusToast } from '../../lib/context/StatusToastContext';
import useNotifyApiError from '../../hooks/useNotifyApiError';
interface FolderNode {
id: Identifier | 'root';
@@ -52,8 +55,6 @@ interface UseDetailWorkspaceResult {
resolveFolderPath: (folderId?: Identifier | 'root') => Array<{ id: Identifier | 'root'; name: string }>;
}
import { listFolderContents } from '../../lib/api/apiClient';
const useDetailWorkspace = ({
documents,
documentLookup,
@@ -77,6 +78,9 @@ const useDetailWorkspace = ({
tagLookupById,
correspondentLookupById,
}: UseDetailWorkspaceArgs): UseDetailWorkspaceResult => {
const { showToast } = useStatusToast();
const notifyApiError = useNotifyApiError();
const {
detailPanelOpen,
detailPanelDocument,
@@ -181,13 +185,39 @@ const useDetailWorkspace = ({
closeDetailPanel();
}, [closeDetailPanel]);
const handleDetailTagAdd = useCallback(
async (doc: Document, value: string, context?: { option?: unknown }) => {
if (!handleDocumentTagAdd) return;
try {
await handleDocumentTagAdd(doc, value, context);
showToast('Tag assigned.', 'success');
} catch (error) {
notifyApiError(error, 'Failed to assign tag.');
}
},
[handleDocumentTagAdd, showToast, notifyApiError],
);
const handleDetailTagRemove = useCallback(
async (docId: any, tagId: any) => {
if (!handleDocumentTagDetach) return;
try {
await handleDocumentTagDetach(docId, tagId);
showToast('Tag removed.', 'success');
} catch (error) {
notifyApiError(error, 'Failed to remove tag.');
}
},
[handleDocumentTagDetach, showToast, notifyApiError],
);
const detailPanelProps = {
document: detailPanelDocument,
tags,
tagLookupById,
correspondentLookupById,
onTagAdd: handleDocumentTagAdd,
onTagRemove: handleDocumentTagDetach,
onTagAdd: handleDetailTagAdd,
onTagRemove: handleDetailTagRemove,
onOpenPreview: openDocumentPreview,
activePreviewId,
onUpdateTitle: handleDocumentTitleUpdate,