feat: adjust frontend document navigation and opening contexts.

This commit is contained in:
2025-12-10 03:56:22 +01:00
parent ae002b99f0
commit c8cc4b4b7c
4 changed files with 19 additions and 12 deletions
@@ -238,7 +238,7 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
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<DesktopWorkspaceProps> = ({
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}
@@ -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<HTMLElement>) => onDocumentDragStart?.(event, doc),
onDragEnd: (event: DragEvent<HTMLElement>) => onDocumentDragEnd?.(event),
@@ -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');
}
}
}
@@ -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<DocumentOpenContextValue>('DocumentOpen');
@@ -24,21 +24,28 @@ export const DocumentOpenProvider: React.FC<DocumentOpenProviderProps> = ({
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);
}