refactor: Consolidate document view props into a shared interface and refine tag drop payload handling.
This commit is contained in:
@@ -8,7 +8,7 @@ import React, {
|
||||
useSyncExternalStore,
|
||||
} from 'react';
|
||||
import { resolveDocumentAssetUrl } from '../asset_manager';
|
||||
import type { EnsureAssetUrl, GetAsset } from '../asset_manager';
|
||||
import type { GetAsset } from '../asset_manager';
|
||||
import { formatTransform } from '../utils/math';
|
||||
import useDocumentDrag from './useDocumentDrag';
|
||||
import PreviewZoomOverlay from '../detail/PreviewZoomOverlay';
|
||||
@@ -118,18 +118,11 @@ type WorkspaceSnapshotState = {
|
||||
initialLoadDone: boolean;
|
||||
};
|
||||
|
||||
interface DesktopWorkspaceProps {
|
||||
entries?: DeskDocument[];
|
||||
onDocumentActivate?: (...args: unknown[]) => void;
|
||||
onDocumentClick?: (...args: unknown[]) => void;
|
||||
onDocumentTagDrop?: (...args: unknown[]) => void;
|
||||
ensureAssetUrl?: EnsureAssetUrl;
|
||||
getDocumentAsset?: GetAsset;
|
||||
activeTagFilters?: Array<Identifier | null>;
|
||||
tenantId?: Identifier | null;
|
||||
viewId?: string | null;
|
||||
documentLinks?: Map<Identifier, unknown> | null;
|
||||
ensureDownloadUrl?: (docId: Identifier, options?: { force?: boolean }) => Promise<unknown>;
|
||||
import type { DocumentsViewProps } from '../documents/panel/DocumentsPanel';
|
||||
|
||||
interface DesktopWorkspaceProps extends DocumentsViewProps {
|
||||
// Override entries if needed, or rely on DocumentsViewProps
|
||||
// entries: DocumentsListEntry[];
|
||||
}
|
||||
|
||||
interface DesktopWorkspaceViewProps {
|
||||
@@ -209,7 +202,22 @@ const DesktopWorkspace: React.FC<DesktopWorkspaceProps> = ({
|
||||
promoteSelectionOrder,
|
||||
} = useWorkspaceSelectionContext();
|
||||
const items = useMemo<DeskDocument[]>(
|
||||
() => (Array.isArray(entries) ? entries.filter((doc): doc is DeskDocument => Boolean(doc)) : []),
|
||||
() => {
|
||||
if (!Array.isArray(entries)) return [];
|
||||
return entries.flatMap((entry: any) => {
|
||||
if (!entry) return [];
|
||||
|
||||
// Handle DocumentsListEntry
|
||||
if ('type' in entry && entry.type === 'document' && entry.document) {
|
||||
return [entry.document as DeskDocument];
|
||||
}
|
||||
if ('type' in entry && entry.type === 'folder') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
},
|
||||
[entries],
|
||||
);
|
||||
|
||||
@@ -938,6 +946,26 @@ function DesktopWorkspaceView({
|
||||
markLayoutDirty,
|
||||
dragTransformsRef,
|
||||
}: DesktopWorkspaceViewProps) {
|
||||
const handleDeskDocumentActivate = useCallback(
|
||||
(docId: Identifier) => {
|
||||
const doc = documentLookup.get(String(docId));
|
||||
if (doc && onDocumentActivate) {
|
||||
onDocumentActivate(doc, undefined as any);
|
||||
}
|
||||
},
|
||||
[documentLookup, onDocumentActivate],
|
||||
);
|
||||
|
||||
const handleDeskDocumentClick = useCallback(
|
||||
(docId: Identifier, event: any) => {
|
||||
const doc = documentLookup.get(String(docId));
|
||||
if (doc && onDocumentClick) {
|
||||
onDocumentClick(doc, event);
|
||||
}
|
||||
},
|
||||
[documentLookup, onDocumentClick],
|
||||
);
|
||||
|
||||
const { handlePointerDown, handlePointerMove, handlePointerUp, handlePointerCancel } =
|
||||
useDocumentDrag({
|
||||
engine,
|
||||
@@ -954,7 +982,7 @@ function DesktopWorkspaceView({
|
||||
recalcVisibleDocIds,
|
||||
settings: dragSettings,
|
||||
containerRef,
|
||||
onDocumentActivate,
|
||||
onDocumentActivate: handleDeskDocumentActivate,
|
||||
selectedDocumentIds,
|
||||
markLayoutDirty,
|
||||
}) as {
|
||||
@@ -974,17 +1002,13 @@ function DesktopWorkspaceView({
|
||||
handlePointerMove,
|
||||
handlePointerUp,
|
||||
handlePointerCancel,
|
||||
onDocumentClick,
|
||||
onDocumentClick: handleDeskDocumentClick,
|
||||
onDocumentStackSelect,
|
||||
onPromoteSelection,
|
||||
onDocumentActivate,
|
||||
onDocumentActivate: handleDeskDocumentActivate,
|
||||
selectedDocumentIds,
|
||||
openOverlayForDoc,
|
||||
}) as {
|
||||
getCardPointerHandlers: (doc: DeskDocument) => React.HTMLAttributes<HTMLDivElement>;
|
||||
handleShellKeyDown: React.KeyboardEventHandler<HTMLDivElement>;
|
||||
focusShell: () => void;
|
||||
};
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
focusShell();
|
||||
|
||||
Reference in New Issue
Block a user