selection cleanup

This commit is contained in:
2025-11-19 00:57:06 +01:00
parent 1764f24243
commit 6923a68837
5 changed files with 39 additions and 20 deletions
+4 -8
View File
@@ -6,7 +6,6 @@ import UploadQueueOverlay from './UploadQueueOverlay';
import useDocumentsWorkspace from '../hooks/documents/useDocumentsWorkspace';
import { useDocumentsPreferences } from './useDocumentsPreferences';
import SettingsRoute from './SettingsRoute';
import { WorkspaceSelectionProvider } from './WorkspaceSelectionContext';
const AppLayout: React.FC = () => {
const documentsPreferences = useDocumentsPreferences();
@@ -17,7 +16,6 @@ const AppLayout: React.FC = () => {
dropOverlayState,
managementModals,
contextValue,
workspaceSelection,
settingsOpen,
closeSettings,
} = useDocumentsWorkspace({
@@ -47,9 +45,8 @@ const AppLayout: React.FC = () => {
}
return (
<WorkspaceSelectionProvider value={workspaceSelection}>
<AppShellContext.Provider value={contextValue}>
<div className="app-shell" ref={shellRef}>
<AppShellContext.Provider value={contextValue}>
<div className="app-shell" ref={shellRef}>
<DropOverlay
active={dropOverlayState.active}
folderName={dropOverlayState.folderName}
@@ -63,9 +60,8 @@ const AppLayout: React.FC = () => {
{settingsOpen ? (
<SettingsRoute open onClose={closeSettings} />
) : null}
</div>
</AppShellContext.Provider>
</WorkspaceSelectionProvider>
</div>
</AppShellContext.Provider>
);
};
+12 -8
View File
@@ -1,16 +1,20 @@
import React, { createContext, useContext } from 'react';
import type useWorkspaceSelection from './useWorkspaceSelection';
type WorkspaceSelectionValue = ReturnType<typeof useWorkspaceSelection> | null;
export type WorkspaceSelectionValue = ReturnType<typeof useWorkspaceSelection>;
const WorkspaceSelectionContext = createContext<WorkspaceSelectionValue>(null);
const WorkspaceSelectionContext = createContext<WorkspaceSelectionValue | null>(null);
export const WorkspaceSelectionProvider: React.FC<{ value: NonNullable<WorkspaceSelectionValue>; children: React.ReactNode }>
= ({ value, children }) => (
<WorkspaceSelectionContext.Provider value={value}>
{children}
</WorkspaceSelectionContext.Provider>
);
interface WorkspaceSelectionProviderProps {
value: WorkspaceSelectionValue;
children: React.ReactNode;
}
export const WorkspaceSelectionProvider: React.FC<WorkspaceSelectionProviderProps> = ({ value, children }) => (
<WorkspaceSelectionContext.Provider value={value}>
{children}
</WorkspaceSelectionContext.Provider>
);
export const useWorkspaceSelectionContext = () => {
const context = useContext(WorkspaceSelectionContext);
@@ -1,4 +1,5 @@
import { useMemo } from 'react';
import type { WorkspaceSelectionValue } from '../../app/WorkspaceSelectionContext';
type Identifier = string | number;
@@ -72,6 +73,7 @@ export interface UseDocumentsPanelPropsArgs {
moveDocumentsToFolder?: (...args: unknown[]) => void;
documentLinks?: Map<Identifier, DocumentLinkLike>;
ensureDownloadUrl?: (documentId: Identifier, options?: { force?: boolean }) => Promise<DocumentLinkLike | null>;
selectionValue: WorkspaceSelectionValue;
}
export type DocumentsPanelProps = ReturnType<typeof useDocumentsPanelProps>;
@@ -128,6 +130,7 @@ const useDocumentsPanelProps = (props: UseDocumentsPanelPropsArgs) => {
moveDocumentsToFolder,
documentLinks,
ensureDownloadUrl,
selectionValue,
} = props;
return useMemo(
@@ -184,6 +187,7 @@ const useDocumentsPanelProps = (props: UseDocumentsPanelPropsArgs) => {
onMoveDocumentsToFolder: moveDocumentsToFolder,
documentLinks,
ensureDownloadUrl,
selectionValue,
}),
[
activeCorrespondentFilters,
@@ -236,6 +240,7 @@ const useDocumentsPanelProps = (props: UseDocumentsPanelPropsArgs) => {
folderOptions,
documentLinks,
ensureDownloadUrl,
selectionValue,
],
);
};
@@ -6,7 +6,11 @@ import DesktopWorkspace from '../../desktop/DesktopWorkspace';
import { isTagTransferEvent } from '../tagTransfer';
import PreviewZoomOverlay from '../../detail/PreviewZoomOverlay';
import { isPointerModifierEvent, isPrimaryPointerEvent } from '../useEntryPointer';
import { useWorkspaceSelectionContext } from '../../app/WorkspaceSelectionContext';
import {
WorkspaceSelectionProvider,
useWorkspaceSelectionContext,
} from '../../app/WorkspaceSelectionContext';
import type { WorkspaceSelectionValue } from '../../app/WorkspaceSelectionContext';
import DocumentsPanelHeader, {
DocumentsPanelHeaderConfig,
DocumentsHeaderBreadcrumb,
@@ -21,17 +25,21 @@ const EntryType = {
document: 'document',
};
interface DocumentsPanelProps {
interface DocumentsPanelInnerProps {
headerLeading?: ReactNode;
onBreadcrumbNavigate?: (crumb: DocumentsHeaderBreadcrumb) => void;
[key: string]: any;
}
interface DocumentsPanelProps extends DocumentsPanelInnerProps {
selectionValue: WorkspaceSelectionValue;
}
const defaultGetDocumentAsset = (_doc?: unknown, _type?: string) => null;
export type DocumentLinkLike = { url?: string | null; contentType?: string | null };
const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
const DocumentsPanelInner: React.FC<DocumentsPanelInnerProps> = ({
headerLeading = null,
onBreadcrumbNavigate,
currentFolderName,
@@ -825,4 +833,10 @@ const DocumentsPanel: React.FC<DocumentsPanelProps> = ({
);
};
const DocumentsPanel: React.FC<DocumentsPanelProps> = ({ selectionValue, ...rest }) => (
<WorkspaceSelectionProvider value={selectionValue}>
<DocumentsPanelInner {...rest} />
</WorkspaceSelectionProvider>
);
export default DocumentsPanel;
@@ -1539,6 +1539,7 @@ const useDocumentsWorkspace = ({
selectFolder,
documentLinks,
ensureDownloadUrl,
selectionValue: selection,
});
const documentsTableProps = useMemo(
@@ -1700,7 +1701,6 @@ const useDocumentsWorkspace = ({
dropOverlayState,
managementModals,
contextValue,
workspaceSelection: selection,
settingsOpen,
closeSettings,
};