From caa0d1eab93da3a94ad86e750cb2366d4069e1ba Mon Sep 17 00:00:00 2001 From: tigeren Date: Wed, 27 Aug 2025 17:16:45 +0000 Subject: [PATCH] refactor: improve path handling in folder viewer - Updated path splitting logic to retain leading slashes for absolute paths while filtering out empty segments. - Enhanced parent path reconstruction to ensure correct navigation within the folder structure. - Improved readability and maintainability of the path management code. --- src/app/folder-viewer/page.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/folder-viewer/page.tsx b/src/app/folder-viewer/page.tsx index 8e83bfc..58b9776 100644 --- a/src/app/folder-viewer/page.tsx +++ b/src/app/folder-viewer/page.tsx @@ -174,12 +174,18 @@ const FolderViewerPage = () => { // Don't allow navigation above library root if (currentPath === libraryRoot) return ''; - const pathParts = currentPath.split('/').filter(part => part.length > 0); + // Split path but keep leading slash for absolute paths + const pathParts = currentPath.split('/'); const libraryParts = libraryRoot.split('/').filter(part => part.length > 0); - if (pathParts.length <= libraryParts.length) return ''; + // Filter out empty parts but keep structure + const filteredPathParts = pathParts.filter(part => part.length > 0); - return pathParts.slice(0, -1).join('/'); + if (filteredPathParts.length <= libraryParts.length) return ''; + + // Reconstruct absolute path + const parentParts = filteredPathParts.slice(0, -1); + return '/' + parentParts.join('/'); }; const handleBackClick = () => {