Skip to content

Commit

Permalink
A few improvements on the Files page (#271)
Browse files Browse the repository at this point in the history
* Ignore hidden files
* Sort alphabetically by name. Put folders first. Ignore empty folders.
  • Loading branch information
pmyszka authored Apr 18, 2024
1 parent 4f45230 commit 86c69d6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/files/FilesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 86c69d6

Please sign in to comment.