From 86c69d67e9374436cd07658b99bfd5c52e43a1bb Mon Sep 17 00:00:00 2001 From: Piotr Myszka Date: Fri, 19 Apr 2024 00:07:44 +0200 Subject: [PATCH] A few improvements on the Files page (#271) * Ignore hidden files * Sort alphabetically by name. Put folders first. Ignore empty folders. --- src/components/files/FilesPage.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/files/FilesPage.tsx b/src/components/files/FilesPage.tsx index 6061d7b2..ea705dad 100644 --- a/src/components/files/FilesPage.tsx +++ b/src/components/files/FilesPage.tsx @@ -67,9 +67,29 @@ const useFileDirectory = (dir: string) => { "file-directory", async () => { const files = await readDir(dir, { recursive: true }); - const filesInfo = await processFiles(files as MetadataOrEntry[]); + const filesInfo = await processFiles( + files.filter((f) => !f.name?.startsWith(".")) as MetadataOrEntry[], + ); - return filesInfo; + return filesInfo + .sort((a, b) => { + return b.name.localeCompare(a.name, "en", { sensitivity: "base" }); + }) + .filter((f) => { + return f.children === undefined || f.children?.length > 0; + }) + .sort((a, b) => { + if (a.children != null && b.children == null) { + return 1; + } + if (a.children != null && b.children != null) { + return 0; + } + if (a.children == null && b.children == null) { + return 0; + } + return -1; + }); }, ); return {