selection fix

This commit is contained in:
2025-11-11 21:50:08 +01:00
parent 8e7a2f3d6c
commit 1111784caa
4 changed files with 29 additions and 26 deletions
@@ -59,6 +59,34 @@ const DocumentsPanel = ({
const showingSearchResults = searchResults !== null;
const rows = showingSearchResults ? searchResults : documents;
const currentFolderId = useMemo(() => {
if (showingSearchResults) {
return null;
}
const trail = Array.isArray(breadcrumbs) ? breadcrumbs : [];
if (trail.length === 0) {
return 'root';
}
return trail[trail.length - 1]?.id || 'root';
}, [breadcrumbs, showingSearchResults]);
const selectionContextRef = useRef(null);
useEffect(() => {
const nextContext = showingSearchResults
? { type: 'search', marker: searchResults }
: { type: 'folder', marker: currentFolderId || 'root' };
const previous = selectionContextRef.current;
selectionContextRef.current = nextContext;
if (!previous) {
return;
}
const changed = previous.type !== nextContext.type
|| previous.marker !== nextContext.marker;
if (changed) {
onClearSelection?.();
}
}, [showingSearchResults, currentFolderId, searchResults, onClearSelection]);
const entries = useMemo(() => {
const list = [];
if (!showingSearchResults) {
@@ -796,7 +796,6 @@ const useDocumentsWorkspace = ({
setDraggedFolderId,
isInvalidFolderDrop,
setCreatingFolder,
clearSelection,
});
const {
+1 -19
View File
@@ -1,4 +1,4 @@
import { useCallback, useMemo, useRef, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';
import {
DEFAULT_FOLDER_NAME,
createRootNode,
@@ -30,8 +30,6 @@ const useFolderTree = ({
const [currentFolder, setCurrentFolder] = useState(null);
const [currentSubfolders, setCurrentSubfolders] = useState([]);
const lastAppliedFolderIdRef = useRef(null);
const {
focusedDocumentId,
setFocusedDocumentId,
@@ -43,9 +41,6 @@ const useFolderTree = ({
const applySelectedFolder = useCallback(
(folderId, contents) => {
const folderChanged = lastAppliedFolderIdRef.current !== folderId;
lastAppliedFolderIdRef.current = folderId;
const subfolders = contents?.subfolders ?? [];
const docs = assetManager.hydrateDocuments(contents?.documents ?? []);
const folderInfo = contents?.folder ?? null;
@@ -68,11 +63,6 @@ const useFolderTree = ({
let mergedSelection = [];
setSelectedEntries((previous) => {
if (folderChanged) {
nextDocKeys = [];
mergedSelection = [];
return [];
}
const previousFolderKeys = previous
.filter(isFolderRowKey)
.filter((key) => availableFolderKeys.has(key));
@@ -82,14 +72,6 @@ const useFolderTree = ({
return mergedSelection;
});
if (folderChanged) {
setFocusedDocumentId(null);
selectionAnchorRef.current = null;
selectionOrderRef.current = [];
setSelectionOrder([]);
return;
}
const nextFocus = (() => {
const currentFocusedKey = resolveDocumentRowKey(focusedDocumentId);
if (currentFocusedKey && availableDocKeySet.has(currentFocusedKey)) {
@@ -28,7 +28,6 @@ const useFolderTreeActions = ({
setDraggedFolderId,
isInvalidFolderDrop,
setCreatingFolder,
clearSelection,
}) => {
const moveFolder = useCallback(
async (folderId, targetFolderId) => {
@@ -174,10 +173,6 @@ const useFolderTreeActions = ({
async (folderId, { replace = false, immediate = false } = {}) => {
const targetId = folderId && folderId !== 'root' ? folderId : 'root';
if (typeof clearSelection === 'function') {
clearSelection();
}
await ensureFolderAncestorsLoaded(targetId);
expandFolderAncestors(targetId);
@@ -191,7 +186,6 @@ const useFolderTreeActions = ({
navigate(path, { replace });
},
[
clearSelection,
ensureFolderAncestorsLoaded,
expandFolderAncestors,
isFilterActive,