diff --git a/frontend/src/app/useDocumentPreview.ts b/frontend/src/app/useDocumentPreview.ts index c1e1192..851fd92 100644 --- a/frontend/src/app/useDocumentPreview.ts +++ b/frontend/src/app/useDocumentPreview.ts @@ -4,14 +4,12 @@ import type { MutableRefObject, SetStateAction, } from 'react'; +import { useNavigate } from 'react-router-dom'; import type { DocumentId } from '../types/identifiers'; type FolderId = DocumentId | 'root'; import type { Document } from '../types/documents'; - -type NavigateHandler = (path: string, options?: { replace?: boolean }) => void; - import useNotifyApiError from '../hooks/useNotifyApiError'; interface UseDocumentPreviewArgs { @@ -24,7 +22,6 @@ interface UseDocumentPreviewArgs { ingest: (docs: unknown[]) => { canonical: Document[]; changed: boolean }; }; selectedFolder?: FolderId | null; - navigate: NavigateHandler; locationPathname: string; locationSearch: string; detailPanelControlRef: MutableRefObject<{ @@ -45,7 +42,6 @@ const useDocumentPreview = ({ routeDocumentId, documentsManager, selectedFolder, - navigate, locationPathname, locationSearch, detailPanelControlRef, @@ -53,6 +49,7 @@ const useDocumentPreview = ({ }: UseDocumentPreviewArgs): UseDocumentPreviewResult => { const previewReturnPathRef = useRef(null); const notifyApiError = useNotifyApiError(); + const navigate = useNavigate(); const resetPreviewState = useCallback(() => { previewReturnPathRef.current = null; diff --git a/frontend/src/app/useDocumentsSearch.ts b/frontend/src/app/useDocumentsSearch.ts index 78eb7b0..981a140 100644 --- a/frontend/src/app/useDocumentsSearch.ts +++ b/frontend/src/app/useDocumentsSearch.ts @@ -1,5 +1,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import type { Dispatch, SetStateAction } from 'react'; +import { useNavigate } from 'react-router-dom'; import { TAG_FILTER_UNTAGGED } from './workspaceUtils'; import { listDocuments } from '../lib/api/apiClient'; import type { Identifier } from '../types/identifiers'; @@ -16,7 +17,6 @@ interface UseDocumentsSearchArgs { api: ApiClient; token?: string | null; selectedFolder?: Identifier | 'root' | null; - navigate?: (path: string, options?: { replace?: boolean }) => void; locationPathname?: string; isDocumentsRoute?: boolean; searchIncludeDescendants?: boolean; @@ -67,7 +67,6 @@ const useDocumentsSearch = ({ api, token, selectedFolder, - navigate, locationPathname, isDocumentsRoute, searchIncludeDescendants, @@ -83,6 +82,7 @@ const useDocumentsSearch = ({ const [searchLoading, setSearchLoading] = useState(false); const [searchTrigger, setSearchTrigger] = useState(0); const notifyApiError = useNotifyApiError(); + const navigate = useNavigate(); const toggleTagFilter = useCallback((tagId: Identifier) => { if (!tagId) return; diff --git a/frontend/src/documents/data/useDocumentsWorkspace.ts b/frontend/src/documents/data/useDocumentsWorkspace.ts index 3539b1d..693c51a 100644 --- a/frontend/src/documents/data/useDocumentsWorkspace.ts +++ b/frontend/src/documents/data/useDocumentsWorkspace.ts @@ -371,7 +371,6 @@ const useDocumentsWorkspace = ({ api: apiClient, token, selectedFolder, - navigate, locationPathname: location.pathname, isDocumentsRoute, searchIncludeDescendants, @@ -444,7 +443,6 @@ const useDocumentsWorkspace = ({ routeDocumentId: previewDocumentId, documentsManager, selectedFolder, - navigate, locationPathname: location.pathname, locationSearch: location.search, detailPanelControlRef, @@ -756,7 +754,6 @@ const useDocumentsWorkspace = ({ setFolderNodes, selectedFolder, setSelectedFolder, - navigate, handleFileDrop, moveDocumentsToFolder, draggedDocumentIds, @@ -1080,14 +1077,12 @@ const useDocumentsWorkspace = ({ }, [selectedFolder, folderNodes]); const { handleTenantSelect } = useTenantManager({ - appDispatch, currentTenantId, resetWorkspaceState, refreshTags, refreshCorrespondents, loadFolder, handleDocumentsViewModeChange, - navigate, tokenRef, tenantIdRef, }); diff --git a/frontend/src/documents/data/useTenantManager.ts b/frontend/src/documents/data/useTenantManager.ts index 4360f9d..047e1ad 100644 --- a/frontend/src/documents/data/useTenantManager.ts +++ b/frontend/src/documents/data/useTenantManager.ts @@ -1,7 +1,9 @@ import { MutableRefObject, useCallback } from 'react'; -import type { NavigateFunction } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; + import type { FolderId, TenantId } from '../../types/identifiers'; import { useStatusToast } from '../../lib/context/StatusToastContext'; +import { useAppDispatch } from '../../lib/store/appState'; import { api, listTenants, switchTenant } from '../../lib/api/apiClient'; @@ -13,32 +15,30 @@ interface TenantOption { import useNotifyApiError from '../../hooks/useNotifyApiError'; interface UseTenantManagerOptions { - appDispatch: (action: any) => void; currentTenantId: TenantId | null; resetWorkspaceState: () => void; refreshTags: () => Promise; refreshCorrespondents: () => Promise; loadFolder: (folderId: FolderId, options?: { preserveSearch?: boolean }) => Promise; handleDocumentsViewModeChange: (mode: string) => void; - navigate: NavigateFunction; tokenRef?: MutableRefObject; tenantIdRef?: MutableRefObject; } const useTenantManager = ({ - appDispatch, currentTenantId, resetWorkspaceState, refreshTags, refreshCorrespondents, loadFolder, handleDocumentsViewModeChange, - navigate, tokenRef, tenantIdRef, }: UseTenantManagerOptions) => { const { showToast } = useStatusToast(); const notifyApiError = useNotifyApiError(); + const navigate = useNavigate(); + const appDispatch = useAppDispatch(); const handleTenantSelect = useCallback( async (tenantOption: TenantOption | null, { refreshOnly = false }: { refreshOnly?: boolean } = {}) => { const requestedTenantId = tenantOption?.id ?? null; diff --git a/frontend/src/documents/features/folders/useFolderTreeActions.ts b/frontend/src/documents/features/folders/useFolderTreeActions.ts index bfa4330..330068f 100644 --- a/frontend/src/documents/features/folders/useFolderTreeActions.ts +++ b/frontend/src/documents/features/folders/useFolderTreeActions.ts @@ -1,4 +1,5 @@ import { useCallback, useMemo } from 'react'; +import { useNavigate } from 'react-router-dom'; import type { DragEvent } from 'react'; import { useStatusToast } from '../../../lib/context/StatusToastContext'; import { DEFAULT_FOLDER_NAME, hasFiles } from '../../../app/workspaceUtils'; @@ -37,7 +38,6 @@ interface UseFolderTreeActionsOptions { setFolderNodes: (updater: (prev: Map) => Map) => void; selectedFolder: FolderKey; setSelectedFolder: (folderId: FolderKey) => void; - navigate?: (path: string, options?: { replace?: boolean }) => void; handleFileDrop: (dataTransfer: DataTransfer, folderId: FolderKey) => Promise | void; moveDocumentsToFolder: (docIds: FolderId[], folderId: FolderKey) => Promise; draggedDocumentIds: FolderId[]; @@ -54,7 +54,6 @@ const useFolderTreeActions = ({ setFolderNodes, selectedFolder, setSelectedFolder, - navigate, handleFileDrop, moveDocumentsToFolder, draggedDocumentIds, @@ -66,6 +65,7 @@ const useFolderTreeActions = ({ }: UseFolderTreeActionsOptions) => { const { showToast } = useStatusToast(); const notifyApiError = useNotifyApiError(); + const navigate = useNavigate(); const moveFolder = useCallback( async (folderId: FolderKey, targetFolderId: FolderKey | null) => {