feat: remove unused canvas focus request from tag interactions.
This commit is contained in:
@@ -9,7 +9,7 @@ import { LayoutStore, LayoutCard } from '../logic/LayoutSystem';
|
||||
import DesktopDocumentCard from './DesktopDocumentCard';
|
||||
import usePreviewMetadata from '../hooks/usePreviewMetadata';
|
||||
import {
|
||||
useTagInteractions,
|
||||
TagInteractionHandlers,
|
||||
} from '../../documents/interactions/useTagInteractions';
|
||||
import './workspace-layout.css';
|
||||
import './workspace-items.css';
|
||||
@@ -22,7 +22,7 @@ import type { DocumentsListEntry, Document } from '../../types/documents';
|
||||
import { useAppState } from '../../lib/store/appState';
|
||||
import { useDocumentOpen } from '../../lib/context/DocumentOpenContext';
|
||||
import { useDocumentsAssetContext } from '../../documents/context/DocumentsAssetContext';
|
||||
import { useDocumentsCommandContext } from '../../documents/context/DocumentsCommandContext';
|
||||
import { useDocumentsViewStateContext } from '../../documents/context/DocumentsViewStateContext';
|
||||
|
||||
interface DocumentSizeInfo {
|
||||
width: number;
|
||||
@@ -41,6 +41,7 @@ interface DesktopWorkspaceProps {
|
||||
onSelectionChange?: (selectedIds: Identifier[]) => void;
|
||||
viewId?: string | null;
|
||||
defaultCardSize?: number;
|
||||
tagHandlers?: TagInteractionHandlers;
|
||||
}
|
||||
|
||||
const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
|
||||
@@ -48,13 +49,13 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
|
||||
onSelectionChange,
|
||||
viewId,
|
||||
defaultCardSize = 200,
|
||||
tagHandlers,
|
||||
}) => {
|
||||
const { openDocument } = useDocumentOpen();
|
||||
const {
|
||||
ensureAssetUrl,
|
||||
getDocumentAsset
|
||||
} = useDocumentsAssetContext();
|
||||
const { tags } = useDocumentsCommandContext();
|
||||
|
||||
const { tenant } = useAppState();
|
||||
const tenantId = tenant?.id as Identifier;
|
||||
@@ -181,22 +182,16 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Tag Interactions
|
||||
const tagHandlers = useTagInteractions({
|
||||
onAssignTagToDocument: (docId: string, tagId: string) => {
|
||||
tags.onAttach?.(docId, tagId);
|
||||
},
|
||||
onRemoveTagFromDocument: (docId: string, tagId: string) => {
|
||||
tags.onDetach?.(docId, tagId);
|
||||
},
|
||||
requestCanvasFocus: focusShell,
|
||||
onTagClick: tags.onClick,
|
||||
});
|
||||
const { scrollRef } = useDocumentsViewStateContext();
|
||||
|
||||
useEffect(() => {
|
||||
const handleWindowKeyDown = (e: KeyboardEvent) => {
|
||||
// Only handle events if the container itself is the target (focused)
|
||||
if (e.target !== containerRef.current) {
|
||||
// Handle events if the container or the shared scrollRef is focused
|
||||
// This allows unified handlers (which focus scrollRef) to work seamlessly with Desktop shortcuts
|
||||
const isTargetContainer = e.target === containerRef.current;
|
||||
const isTargetScrollRef = scrollRef && e.target === scrollRef.current;
|
||||
|
||||
if (!isTargetContainer && !isTargetScrollRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,7 +313,7 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
|
||||
|
||||
window.addEventListener('keydown', handleWindowKeyDown);
|
||||
return () => window.removeEventListener('keydown', handleWindowKeyDown);
|
||||
}, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange]);
|
||||
}, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange, scrollRef]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -47,7 +47,6 @@ const cleanupPreview = (previewNode: HTMLElement | null) => {
|
||||
interface UseTagInteractionsArgs {
|
||||
onAssignTagToDocument?: (docId: Identifier, tagId: Identifier) => void;
|
||||
onRemoveTagFromDocument?: (docId: Identifier, tagId: Identifier) => void;
|
||||
requestCanvasFocus?: () => void;
|
||||
onTagClick?: (tagId: Identifier) => void;
|
||||
}
|
||||
|
||||
@@ -69,7 +68,6 @@ export interface TagInteractionHandlers {
|
||||
export const useTagInteractions = ({
|
||||
onAssignTagToDocument,
|
||||
onRemoveTagFromDocument,
|
||||
requestCanvasFocus,
|
||||
onTagClick,
|
||||
}: UseTagInteractionsArgs): TagInteractionHandlers => {
|
||||
const draggingTagRef = useRef<DraggingTagState | null>(null);
|
||||
@@ -155,8 +153,6 @@ export const useTagInteractions = ({
|
||||
return;
|
||||
}
|
||||
|
||||
requestCanvasFocus?.();
|
||||
|
||||
// Double-check assignment (even though cursor logic tries to prevent it)
|
||||
const isAssigned = doc.tags?.some((t) => t.id === payload.id);
|
||||
if (isAssigned) return;
|
||||
@@ -166,7 +162,7 @@ export const useTagInteractions = ({
|
||||
}
|
||||
}, 0);
|
||||
},
|
||||
[isTagTransfer, onAssignTagToDocument, requestCanvasFocus],
|
||||
[isTagTransfer, onAssignTagToDocument],
|
||||
);
|
||||
|
||||
const onTagDragStart = useCallback(
|
||||
|
||||
@@ -37,6 +37,9 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => {
|
||||
toggleCorrespondent: toggleCorrespondentFilter,
|
||||
} = useDocumentsFilter();
|
||||
|
||||
const scrollRef = useRef<HTMLElement | null>(null);
|
||||
const suppressDocumentClickRef = useRef(false);
|
||||
|
||||
// Handlers
|
||||
const tagHandlers = useTagInteractions({
|
||||
onAssignTagToDocument: props.onDocumentTagAttach,
|
||||
@@ -73,10 +76,6 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => {
|
||||
selectedFolder,
|
||||
]);
|
||||
|
||||
// Refs
|
||||
const scrollRef = useRef<HTMLElement | null>(null);
|
||||
const suppressDocumentClickRef = useRef(false);
|
||||
|
||||
const handleFolderClick = useCallback(
|
||||
(folder: any, event: any) => {
|
||||
if (!folder) {
|
||||
|
||||
Reference in New Issue
Block a user