feat: Introduce DocumentOpenContext for document activation in the frontend

This commit is contained in:
2025-12-04 00:57:54 +01:00
parent 65555c18e8
commit 447b012e48
9 changed files with 82 additions and 50 deletions
+8 -7
View File
@@ -18,8 +18,8 @@ import { createDocumentEntryKey } from '../app/entryKey';
import { PointerTrackingProvider, usePointerTracking } from './PointerTrackingContext';
import type { Identifier } from '../types/identifiers';
import type { DocumentsListEntry, Document } from '../types/documents';
import { usePreviewContext } from '../preview/PreviewContext';
import { useAppState } from '../app/appState';
import { useDocumentOpen } from '../context/DocumentOpenContext';
type TagLike = { id?: Identifier | null; label?: string; color?: string | null } | null;
type OverlaySource = { url: string; alt?: string | null; mimeType?: string | null; };
@@ -48,7 +48,6 @@ export interface DesktopWorkspaceProps {
entries: DocumentsListEntry[];
ensureAssetUrl?: (...args: any[]) => Promise<unknown>;
getDocumentAsset?: (...args: any[]) => unknown;
onDocumentActivate?: (doc: DeskDocument, event?: unknown) => void;
onSelectionChange?: (selectedIds: Identifier[]) => void;
onDocumentTagAttach?: (docId: Identifier, tagId: Identifier) => void;
onDocumentTagDetach?: (docId: Identifier, tagId: Identifier) => void;
@@ -83,14 +82,13 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
entries,
ensureAssetUrl,
getDocumentAsset,
onDocumentActivate,
onSelectionChange,
onDocumentTagAttach,
onDocumentTagDetach,
viewId,
defaultCardSize = 200,
}) => {
const { openPreview } = usePreviewContext();
const { openDocument } = useDocumentOpen();
const { tenant } = useAppState();
const tenantId = tenant?.id as Identifier;
const { addPointer, removePointer } = usePointerTracking();
@@ -240,7 +238,7 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
const doc = items.find(i => String(i.id) === lastId);
if (doc) {
e.preventDefault();
openPreview(doc);
openDocument(doc, 'preview');
return;
}
}
@@ -352,7 +350,7 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
window.addEventListener('keydown', handleWindowKeyDown);
return () => window.removeEventListener('keydown', handleWindowKeyDown);
}, [selectedDocumentIds, items, openPreview, layoutStore, handleSelectionChange]);
}, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange]);
return (
<>
@@ -424,7 +422,10 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
ensureAssetUrl={ensureAssetUrl}
getDocumentAsset={getDocumentAsset}
handleNavigatorSnapshot={() => { }}
onDocumentActivate={(_id, event) => { onDocumentActivate?.(doc, event) }}
onDocumentActivate={(_id, event) => {
const isPreview = event && ((event as any).altKey || (event as any).button === 1);
openDocument(doc, isPreview ? 'preview' : 'sidepanel');
}}
layoutCard={layoutCard}
onTagDragEnter={tagInteractions.handleTagDragEnterDoc}
onTagDragOver={tagInteractions.handleTagDragOverDoc}