From c8cc4b4b7c55d8cee3154be8c57abc76103dd396 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 10 Dec 2025 03:49:15 +0100 Subject: [PATCH] feat: adjust frontend document navigation and opening contexts. --- .../desktop/components/DesktopWorkspace.tsx | 4 ++-- .../documents/logic/useDocumentItemLogic.ts | 2 +- .../documents/logic/useDocumentsNavigation.ts | 2 +- .../src/lib/context/DocumentOpenContext.tsx | 23 ++++++++++++------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/frontend/src/desktop/components/DesktopWorkspace.tsx b/frontend/src/desktop/components/DesktopWorkspace.tsx index 8f0e036..df12538 100644 --- a/frontend/src/desktop/components/DesktopWorkspace.tsx +++ b/frontend/src/desktop/components/DesktopWorkspace.tsx @@ -238,7 +238,7 @@ const DesktopWorkspaceContent: React.FC = ({ const doc = items.find(i => String(i.id) === lastId); if (doc) { e.preventDefault(); - const target = e.code === 'Enter' ? 'sidepanel' : 'preview'; + const target = e.code === 'Enter' ? 'inspect' : 'preview'; openDocument(doc, target); return; } @@ -416,7 +416,7 @@ const DesktopWorkspaceContent: React.FC = ({ getDocumentAsset={getDocumentAsset} onDocumentActivate={(_id, event) => { const isPreview = event && ((event as any).altKey || (event as any).button === 1); - openDocument(doc, isPreview ? 'preview' : 'sidepanel'); + openDocument(doc, isPreview ? 'preview' : 'inspect'); }} layoutCard={layoutCard} tagHandlers={tagHandlers} diff --git a/frontend/src/documents/logic/useDocumentItemLogic.ts b/frontend/src/documents/logic/useDocumentItemLogic.ts index ba7f6cf..d9d6b19 100644 --- a/frontend/src/documents/logic/useDocumentItemLogic.ts +++ b/frontend/src/documents/logic/useDocumentItemLogic.ts @@ -65,7 +65,7 @@ export const useDocumentItemLogic = ({ doc, tagHandlers, viewLogic }: UseDocumen }, onDoubleClick: (event: React.MouseEvent) => { const isPreview = event && (event.altKey || event.button === 1); - openDocument(doc, isPreview ? 'preview' : 'sidepanel'); + openDocument(doc, isPreview ? 'preview' : 'inspect'); }, onDragStart: (event: DragEvent) => onDocumentDragStart?.(event, doc), onDragEnd: (event: DragEvent) => onDocumentDragEnd?.(event), diff --git a/frontend/src/documents/logic/useDocumentsNavigation.ts b/frontend/src/documents/logic/useDocumentsNavigation.ts index 988c861..55cdeb1 100644 --- a/frontend/src/documents/logic/useDocumentsNavigation.ts +++ b/frontend/src/documents/logic/useDocumentsNavigation.ts @@ -111,7 +111,7 @@ export const useDocumentsNavigation = ({ const entry = getEntryByKey(activeRow.key); if (entry && entry.type === 'document') { const isPreview = key === ' ' || key === 'Space' || key === 'Spacebar'; - openDocument(entry.document, isPreview ? 'preview' : 'sidepanel'); + openDocument(entry.document, isPreview ? 'preview' : 'inspect'); } } } diff --git a/frontend/src/lib/context/DocumentOpenContext.tsx b/frontend/src/lib/context/DocumentOpenContext.tsx index 007f441..ba187b5 100644 --- a/frontend/src/lib/context/DocumentOpenContext.tsx +++ b/frontend/src/lib/context/DocumentOpenContext.tsx @@ -3,10 +3,10 @@ import type { Document } from '../../types/documents'; import type { Identifier } from '../../types/identifiers'; import { createSafeContext } from '../../utils/createSafeContext'; -type DocumentOpenTarget = 'preview' | 'sidepanel' | 'viewer'; +type DocumentOpenIntent = 'preview' | 'inspect' | 'navigate'; interface DocumentOpenContextValue { - openDocument: (doc: Document, target?: DocumentOpenTarget) => void; + openDocument: (doc: Document, intent?: DocumentOpenIntent) => void; } const [DocumentOpenContext, useDocumentOpen] = createSafeContext('DocumentOpen'); @@ -24,21 +24,28 @@ export const DocumentOpenProvider: React.FC = ({ onOpenPreview, onOpenDetailPanel, }) => { - const openDocument = useCallback((doc: Document, target: DocumentOpenTarget = 'preview') => { + const openDocument = useCallback((doc: Document, intent: DocumentOpenIntent = 'preview') => { if (!doc) return; - switch (target) { + switch (intent) { case 'preview': if (onOpenPreview) { onOpenPreview(doc); } break; - case 'sidepanel': - if (onOpenDetailPanel) { - onOpenDetailPanel(doc.id); + case 'inspect': + // Responsive behavior: on mobile, "inspect" just navigates to the document + if (window.matchMedia('(max-width: 768px)').matches) { + if (onOpenViewer) { + onOpenViewer(doc.id); + } + } else { + if (onOpenDetailPanel) { + onOpenDetailPanel(doc.id); + } } break; - case 'viewer': + case 'navigate': if (onOpenViewer) { onOpenViewer(doc.id); }