feat: remove unused canvas focus request from tag interactions.

This commit is contained in:
2025-12-09 00:17:16 +01:00
parent 99fa12a1be
commit f3292211a8
3 changed files with 16 additions and 26 deletions
@@ -9,7 +9,7 @@ import { LayoutStore, LayoutCard } from '../logic/LayoutSystem';
import DesktopDocumentCard from './DesktopDocumentCard'; import DesktopDocumentCard from './DesktopDocumentCard';
import usePreviewMetadata from '../hooks/usePreviewMetadata'; import usePreviewMetadata from '../hooks/usePreviewMetadata';
import { import {
useTagInteractions, TagInteractionHandlers,
} from '../../documents/interactions/useTagInteractions'; } from '../../documents/interactions/useTagInteractions';
import './workspace-layout.css'; import './workspace-layout.css';
import './workspace-items.css'; import './workspace-items.css';
@@ -22,7 +22,7 @@ import type { DocumentsListEntry, Document } from '../../types/documents';
import { useAppState } from '../../lib/store/appState'; import { useAppState } from '../../lib/store/appState';
import { useDocumentOpen } from '../../lib/context/DocumentOpenContext'; import { useDocumentOpen } from '../../lib/context/DocumentOpenContext';
import { useDocumentsAssetContext } from '../../documents/context/DocumentsAssetContext'; import { useDocumentsAssetContext } from '../../documents/context/DocumentsAssetContext';
import { useDocumentsCommandContext } from '../../documents/context/DocumentsCommandContext'; import { useDocumentsViewStateContext } from '../../documents/context/DocumentsViewStateContext';
interface DocumentSizeInfo { interface DocumentSizeInfo {
width: number; width: number;
@@ -41,6 +41,7 @@ interface DesktopWorkspaceProps {
onSelectionChange?: (selectedIds: Identifier[]) => void; onSelectionChange?: (selectedIds: Identifier[]) => void;
viewId?: string | null; viewId?: string | null;
defaultCardSize?: number; defaultCardSize?: number;
tagHandlers?: TagInteractionHandlers;
} }
const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
@@ -48,13 +49,13 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
onSelectionChange, onSelectionChange,
viewId, viewId,
defaultCardSize = 200, defaultCardSize = 200,
tagHandlers,
}) => { }) => {
const { openDocument } = useDocumentOpen(); const { openDocument } = useDocumentOpen();
const { const {
ensureAssetUrl, ensureAssetUrl,
getDocumentAsset getDocumentAsset
} = useDocumentsAssetContext(); } = useDocumentsAssetContext();
const { tags } = useDocumentsCommandContext();
const { tenant } = useAppState(); const { tenant } = useAppState();
const tenantId = tenant?.id as Identifier; const tenantId = tenant?.id as Identifier;
@@ -181,22 +182,16 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
} }
}, []); }, []);
// Tag Interactions const { scrollRef } = useDocumentsViewStateContext();
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,
});
useEffect(() => { useEffect(() => {
const handleWindowKeyDown = (e: KeyboardEvent) => { const handleWindowKeyDown = (e: KeyboardEvent) => {
// Only handle events if the container itself is the target (focused) // Handle events if the container or the shared scrollRef is focused
if (e.target !== containerRef.current) { // 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; return;
} }
@@ -318,7 +313,7 @@ const DesktopWorkspaceContent: React.FC<DesktopWorkspaceProps> = ({
window.addEventListener('keydown', handleWindowKeyDown); window.addEventListener('keydown', handleWindowKeyDown);
return () => window.removeEventListener('keydown', handleWindowKeyDown); return () => window.removeEventListener('keydown', handleWindowKeyDown);
}, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange]); }, [selectedDocumentIds, items, openDocument, layoutStore, handleSelectionChange, scrollRef]);
return ( return (
<> <>
@@ -47,7 +47,6 @@ const cleanupPreview = (previewNode: HTMLElement | null) => {
interface UseTagInteractionsArgs { interface UseTagInteractionsArgs {
onAssignTagToDocument?: (docId: Identifier, tagId: Identifier) => void; onAssignTagToDocument?: (docId: Identifier, tagId: Identifier) => void;
onRemoveTagFromDocument?: (docId: Identifier, tagId: Identifier) => void; onRemoveTagFromDocument?: (docId: Identifier, tagId: Identifier) => void;
requestCanvasFocus?: () => void;
onTagClick?: (tagId: Identifier) => void; onTagClick?: (tagId: Identifier) => void;
} }
@@ -69,7 +68,6 @@ export interface TagInteractionHandlers {
export const useTagInteractions = ({ export const useTagInteractions = ({
onAssignTagToDocument, onAssignTagToDocument,
onRemoveTagFromDocument, onRemoveTagFromDocument,
requestCanvasFocus,
onTagClick, onTagClick,
}: UseTagInteractionsArgs): TagInteractionHandlers => { }: UseTagInteractionsArgs): TagInteractionHandlers => {
const draggingTagRef = useRef<DraggingTagState | null>(null); const draggingTagRef = useRef<DraggingTagState | null>(null);
@@ -155,8 +153,6 @@ export const useTagInteractions = ({
return; return;
} }
requestCanvasFocus?.();
// Double-check assignment (even though cursor logic tries to prevent it) // Double-check assignment (even though cursor logic tries to prevent it)
const isAssigned = doc.tags?.some((t) => t.id === payload.id); const isAssigned = doc.tags?.some((t) => t.id === payload.id);
if (isAssigned) return; if (isAssigned) return;
@@ -166,7 +162,7 @@ export const useTagInteractions = ({
} }
}, 0); }, 0);
}, },
[isTagTransfer, onAssignTagToDocument, requestCanvasFocus], [isTagTransfer, onAssignTagToDocument],
); );
const onTagDragStart = useCallback( const onTagDragStart = useCallback(
@@ -37,6 +37,9 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => {
toggleCorrespondent: toggleCorrespondentFilter, toggleCorrespondent: toggleCorrespondentFilter,
} = useDocumentsFilter(); } = useDocumentsFilter();
const scrollRef = useRef<HTMLElement | null>(null);
const suppressDocumentClickRef = useRef(false);
// Handlers // Handlers
const tagHandlers = useTagInteractions({ const tagHandlers = useTagInteractions({
onAssignTagToDocument: props.onDocumentTagAttach, onAssignTagToDocument: props.onDocumentTagAttach,
@@ -73,10 +76,6 @@ export const useDocumentsContextValues = (props: DocumentsPanelInnerProps) => {
selectedFolder, selectedFolder,
]); ]);
// Refs
const scrollRef = useRef<HTMLElement | null>(null);
const suppressDocumentClickRef = useRef(false);
const handleFolderClick = useCallback( const handleFolderClick = useCallback(
(folder: any, event: any) => { (folder: any, event: any) => {
if (!folder) { if (!folder) {