feat: enhance frontend tag operations with UI notifications.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user