feat: Introduce DocumentOpenContext for document activation in the frontend
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import type { DocumentsListEntry } from '../../types/documents';
|
||||
import { useWorkspaceSelectionContext } from '../../app/WorkspaceSelectionContext';
|
||||
import { useDocumentOpen } from '../../context/DocumentOpenContext';
|
||||
|
||||
interface UseDocumentsNavigationProps {
|
||||
entries: DocumentsListEntry[];
|
||||
onFolderSelect?: (folderId: string) => void;
|
||||
onPreview?: (doc: any) => void;
|
||||
viewMode?: string;
|
||||
scrollRef?: React.RefObject<HTMLElement | null>;
|
||||
}
|
||||
@@ -13,7 +13,6 @@ interface UseDocumentsNavigationProps {
|
||||
export const useDocumentsNavigation = ({
|
||||
entries,
|
||||
onFolderSelect,
|
||||
onPreview,
|
||||
viewMode,
|
||||
scrollRef,
|
||||
}: UseDocumentsNavigationProps) => {
|
||||
@@ -25,6 +24,8 @@ export const useDocumentsNavigation = ({
|
||||
applySelection,
|
||||
} = useWorkspaceSelectionContext();
|
||||
|
||||
const { openDocument } = useDocumentOpen();
|
||||
|
||||
const navigableRows = useMemo(
|
||||
() => entries.map((entry) => ({ key: entry.key, type: entry.type, id: entry.id })),
|
||||
[entries],
|
||||
@@ -109,7 +110,8 @@ export const useDocumentsNavigation = ({
|
||||
} else {
|
||||
const entry = getEntryByKey(activeRow.key);
|
||||
if (entry && entry.type === 'document') {
|
||||
onPreview?.(entry.document);
|
||||
const isPreview = key === ' ' || key === 'Space' || key === 'Spacebar';
|
||||
openDocument(entry.document, isPreview ? 'preview' : 'sidepanel');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,7 +177,7 @@ export const useDocumentsNavigation = ({
|
||||
navigableRows,
|
||||
onFolderSelect,
|
||||
selectedEntries,
|
||||
onPreview,
|
||||
openDocument,
|
||||
handleEntrySelection,
|
||||
setFocusedEntryKey,
|
||||
viewMode,
|
||||
|
||||
Reference in New Issue
Block a user