From 816c880e8ef2ed3909629712ee18de2f802de4dd Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sat, 1 Nov 2025 13:40:10 +0100 Subject: [PATCH] cleanup --- frontend/src/app/AppLayout.jsx | 23 +++++++++++++++-------- frontend/src/styles.css | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/AppLayout.jsx b/frontend/src/app/AppLayout.jsx index 49a0ecd..ec66ad5 100644 --- a/frontend/src/app/AppLayout.jsx +++ b/frontend/src/app/AppLayout.jsx @@ -316,6 +316,7 @@ const AppLayout = () => { const [searchResults, setSearchResults] = useState(null); const [previewEntries, setPreviewEntries] = useState(() => new Map()); const previewInflightRef = useRef(new Map()); + const previewReturnPathRef = useRef(null); const [tags, setTags] = useState([]); const [correspondents, setCorrespondents] = useState([]); const [webdavTokens, setWebdavTokens] = useState([]); @@ -3358,10 +3359,10 @@ const AppLayout = () => { }); } - const targetFolder = doc?.folder_id || selectedFolder || 'root'; - if (targetFolder && targetFolder !== selectedFolder) { - await loadFolder(targetFolder, { showLoading: false, preserveSearch: isFilterActive }); - doc = findInCache() || doc; + if (!previewReturnPathRef.current) { + const fallbackFolderId = doc?.folder_id || 'root'; + previewReturnPathRef.current = + fallbackFolderId === 'root' ? '/documents' : `/documents/folder/${fallbackFolderId}`; } await ensurePreviewUrl(documentId, { force: false }); @@ -3373,9 +3374,6 @@ const AppLayout = () => { documents, assetManager, setDocuments, - selectedFolder, - loadFolder, - isFilterActive, ensurePreviewUrl, setActivePreviewId, ], @@ -3384,13 +3382,22 @@ const AppLayout = () => { const openDocumentPreview = useCallback( (documentId, { replace = false } = {}) => { if (!documentId) return; + previewReturnPathRef.current = `${location.pathname}${location.search}`; navigate(`/documents/${documentId}`, { replace }); }, - [navigate], + [navigate, location.pathname, location.search], ); const closeDocumentPreview = useCallback( (folderId = null) => { + const fallbackPath = previewReturnPathRef.current; + previewReturnPathRef.current = null; + + if (fallbackPath) { + navigate(fallbackPath, { replace: false }); + return; + } + const targetId = folderId || selectedFolder || 'root'; const path = targetId === 'root' ? '/documents' : `/documents/folder/${targetId}`; navigate(path, { replace: false }); diff --git a/frontend/src/styles.css b/frontend/src/styles.css index ed39f33..3f5bfc8 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -862,7 +862,7 @@ button.danger:hover:not([disabled]) { .preview-workspace__details { display: flex; flex-direction: column; - gap: 1.5rem; + gap: 0.5rem; overflow-y: auto; min-height: 0; }