feat: Centralize document preview logic into useDocumentPreview and add correspondentLookupByName to useCorrespondents
This commit is contained in:
@@ -273,6 +273,13 @@ const useDocumentsWorkspace = ({
|
||||
foldersManager,
|
||||
};
|
||||
|
||||
const resolveFolderPath = useCallback(
|
||||
(folderId) => {
|
||||
return resolveBreadcrumbs(folderId || 'root', folderNodes as any);
|
||||
},
|
||||
[folderNodes],
|
||||
);
|
||||
|
||||
const [currentSubfolders, setCurrentSubfolders] = useState<Array<{ id?: FolderNodeId; name?: string | null;[key: string]: unknown }>>([]);
|
||||
|
||||
const foldersSnapshot = useSyncExternalStore(
|
||||
@@ -384,18 +391,7 @@ const useDocumentsWorkspace = ({
|
||||
}
|
||||
}, [selectedFolder, documentsSortField, documentsSortDirection, fetchFolderData, updateViewState, notifyApiError]);
|
||||
|
||||
const {
|
||||
searchQuery,
|
||||
setSearchQuery,
|
||||
searchResultIds,
|
||||
setSearchResultIds,
|
||||
searchLoading,
|
||||
activeTagFilters,
|
||||
setActiveTagFilters,
|
||||
activeCorrespondentFilters,
|
||||
setActiveCorrespondentFilters,
|
||||
documentsFilterValue,
|
||||
} = useDocumentsSearch({
|
||||
const documentsSearch = useDocumentsSearch({
|
||||
api: apiClient,
|
||||
selectedFolder,
|
||||
locationPathname: location.pathname,
|
||||
@@ -407,8 +403,8 @@ const useDocumentsWorkspace = ({
|
||||
documentsManager,
|
||||
});
|
||||
|
||||
const documentsFilter = documentsFilterValue;
|
||||
const showingSearchResults = searchResultIds !== null;
|
||||
const documentsFilter = documentsSearch.documentsFilterValue;
|
||||
const showingSearchResults = documentsSearch.searchResultIds !== null;
|
||||
|
||||
// Live Filter: Ensure we only show documents that actually belong to the current folder.
|
||||
// Since 'documents' is reactive, if a document is moved, its folder_id updates immediately.
|
||||
@@ -431,7 +427,7 @@ const useDocumentsWorkspace = ({
|
||||
} = useWorkspaceViewData({
|
||||
documents: liveFilteredDocuments,
|
||||
documentLookup,
|
||||
searchResultIds,
|
||||
searchResultIds: documentsSearch.searchResultIds,
|
||||
showingSearchResults,
|
||||
currentSubfolders: visibleSubfolders,
|
||||
});
|
||||
@@ -440,6 +436,8 @@ const useDocumentsWorkspace = ({
|
||||
openDocumentPreview,
|
||||
closeDocumentPreview,
|
||||
resetPreviewState,
|
||||
previewWorkspaceDocument,
|
||||
previewActive,
|
||||
} = useDocumentPreview({
|
||||
routeDocumentId: previewDocumentId,
|
||||
documentsManager,
|
||||
@@ -471,7 +469,7 @@ const useDocumentsWorkspace = ({
|
||||
|
||||
useWorkspaceSelectionSync({
|
||||
showingSearchResults,
|
||||
searchQuery,
|
||||
searchQuery: documentsSearch.searchQuery,
|
||||
setSelectedEntries,
|
||||
setSelectionOrder,
|
||||
selectionOrderRef,
|
||||
@@ -486,7 +484,7 @@ const useDocumentsWorkspace = ({
|
||||
const tagsState = useTags({
|
||||
tenantIdRef,
|
||||
tagManager,
|
||||
setActiveTagFilters,
|
||||
setActiveTagFilters: documentsSearch.setActiveTagFilters,
|
||||
documentsManager,
|
||||
});
|
||||
|
||||
@@ -584,10 +582,10 @@ const useDocumentsWorkspace = ({
|
||||
selectionAnchorRef.current = null;
|
||||
setDraggedDocumentIds([]);
|
||||
setDraggedFolderId(null);
|
||||
setSearchResultIds(null);
|
||||
setSearchQuery('');
|
||||
setActiveTagFilters([]);
|
||||
setActiveCorrespondentFilters([]);
|
||||
documentsSearch.setSearchResultIds(null);
|
||||
documentsSearch.setSearchQuery('');
|
||||
documentsSearch.setActiveTagFilters([]);
|
||||
documentsSearch.setActiveCorrespondentFilters([]);
|
||||
setActivePreviewId(null);
|
||||
detailPanelControlRef.current.close();
|
||||
assetManager.reset();
|
||||
@@ -612,10 +610,7 @@ const useDocumentsWorkspace = ({
|
||||
setDocuments,
|
||||
setDraggedDocumentIds,
|
||||
setDraggedFolderId,
|
||||
setSearchResultIds,
|
||||
setSearchQuery,
|
||||
setActiveTagFilters,
|
||||
setActiveCorrespondentFilters,
|
||||
documentsSearch,
|
||||
setActivePreviewId,
|
||||
resetPreviewState,
|
||||
upload,
|
||||
@@ -631,16 +626,12 @@ const useDocumentsWorkspace = ({
|
||||
const documentsState = {
|
||||
documentLookup,
|
||||
setDocuments,
|
||||
setSearchResultIds,
|
||||
setSearchResultIds: documentsSearch.setSearchResultIds,
|
||||
documentsManager,
|
||||
extractDocumentFromResponse,
|
||||
ingestDocuments: (docs: unknown[]) => documentsManager.ingest(docs),
|
||||
};
|
||||
|
||||
const actionsState = {
|
||||
closeDocumentPreview,
|
||||
};
|
||||
|
||||
const documentMutationsResult = useDocumentMutations({
|
||||
documentsState,
|
||||
folderState,
|
||||
@@ -653,13 +644,12 @@ const useDocumentsWorkspace = ({
|
||||
...correspondentsState,
|
||||
correspondentManager,
|
||||
},
|
||||
actions: actionsState,
|
||||
closeDocumentPreview,
|
||||
previewDocumentId,
|
||||
});
|
||||
|
||||
const {
|
||||
moveDocumentsToFolder,
|
||||
handleThumbnailRegeneration,
|
||||
handleDocumentsDelete,
|
||||
handleDocumentTagAdd,
|
||||
handleDocumentTagAttach,
|
||||
@@ -669,7 +659,6 @@ const useDocumentsWorkspace = ({
|
||||
handleDocumentCorrespondentAttach,
|
||||
handleDocumentCorrespondentDetach,
|
||||
handleDocumentCorrespondentAdd,
|
||||
correspondentLookupByName,
|
||||
} = documentMutationsResult;
|
||||
|
||||
const mutations = {
|
||||
@@ -802,7 +791,7 @@ const useDocumentsWorkspace = ({
|
||||
handleDeleteSelection,
|
||||
} = useBulkDocumentActions({
|
||||
resolveTargetDocumentIds,
|
||||
correspondentLookupByName,
|
||||
correspondentLookupByName: correspondentsState.correspondentLookupByName,
|
||||
handleCorrespondentCreate: correspondentsState.handleCorrespondentCreate,
|
||||
selectedDocumentIds,
|
||||
selectedFolderIds,
|
||||
@@ -874,7 +863,8 @@ const useDocumentsWorkspace = ({
|
||||
onTagDelete: async (tagId: string) => { await tagsState.handleTagDelete(tagId); },
|
||||
correspondents: correspondentsState.correspondents,
|
||||
correspondentLookupById: correspondentsState.correspondentLookupById,
|
||||
refreshCorrespondents: correspondentsState.refreshCorrespondents,
|
||||
correspondentLookupByName: correspondentsState.correspondentLookupByName,
|
||||
refreshCorrespondents,
|
||||
onCorrespondentCreate: correspondentsState.handleCorrespondentCreate,
|
||||
onCorrespondentUpdate: correspondentsState.handleCorrespondentUpdate,
|
||||
onCorrespondentDelete: correspondentsState.handleCorrespondentDelete,
|
||||
@@ -903,21 +893,11 @@ const useDocumentsWorkspace = ({
|
||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||
}, [settingsOpen]);
|
||||
|
||||
const {
|
||||
detailPanelProps,
|
||||
detailPanelOpen,
|
||||
openDetailPanel,
|
||||
previewActive,
|
||||
previewWorkspaceDocument,
|
||||
resolveFolderPath,
|
||||
} = useDetailWorkspace({
|
||||
documents: viewDocuments,
|
||||
const detailPanel = useDetailWorkspace({
|
||||
documentLookup,
|
||||
folderNodes,
|
||||
detailPanelControlRef,
|
||||
detailFolderFetchRef,
|
||||
previewDocumentId,
|
||||
activePreviewId,
|
||||
openDocumentPreview: openDocumentPreviewForDetail,
|
||||
handleDocumentTitleUpdate,
|
||||
handleDocumentIssuedUpdate,
|
||||
@@ -932,6 +912,7 @@ const useDocumentsWorkspace = ({
|
||||
tags: tagsState.tags,
|
||||
tagLookupById: tagsState.tagLookupById,
|
||||
correspondentLookupById: correspondentsState.correspondentLookupById,
|
||||
resolveFolderPath,
|
||||
});
|
||||
|
||||
const handleEntryPointerCore = useEntryPointerCore({
|
||||
@@ -985,7 +966,7 @@ const useDocumentsWorkspace = ({
|
||||
const tags = {
|
||||
...tagsState,
|
||||
tagManager,
|
||||
activeTagFilters,
|
||||
activeTagFilters: documentsSearch.activeTagFilters,
|
||||
// Add derived/action handlers that were previously in tagsContext
|
||||
handleDocumentTagAttach,
|
||||
handleDocumentTagDetach,
|
||||
@@ -996,7 +977,7 @@ const useDocumentsWorkspace = ({
|
||||
|
||||
const correspondents = {
|
||||
...correspondentsState,
|
||||
activeCorrespondentFilters,
|
||||
activeCorrespondentFilters: documentsSearch.activeCorrespondentFilters,
|
||||
// Add derived/action handlers
|
||||
handleDocumentCorrespondentAttach,
|
||||
handleDocumentCorrespondentDetach,
|
||||
@@ -1013,26 +994,19 @@ const useDocumentsWorkspace = ({
|
||||
closeDocumentPreview,
|
||||
ensureAssetUrl,
|
||||
getDocumentAsset,
|
||||
handleThumbnailRegeneration,
|
||||
};
|
||||
|
||||
const detailPanel = {
|
||||
detailPanelProps,
|
||||
detailPanelOpen,
|
||||
openDetailPanel,
|
||||
};
|
||||
|
||||
const search = {
|
||||
searchQuery,
|
||||
searchQuery: documentsSearch.searchQuery,
|
||||
documentsFilter,
|
||||
searchLoading,
|
||||
searchLoading: documentsSearch.searchLoading,
|
||||
documentsViewMode,
|
||||
handleDocumentsViewModeChange,
|
||||
documentsSortField,
|
||||
documentsSortDirection,
|
||||
handleDocumentsSortFieldChange,
|
||||
handleDocumentsSortDirectionToggle,
|
||||
searchResultIds,
|
||||
searchResultIds: documentsSearch.searchResultIds,
|
||||
documents: viewDocuments,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user