From da87d75b5b2ad000bc07caf7a9b5b0c21abfaa6e Mon Sep 17 00:00:00 2001 From: Murilo Polese Date: Thu, 11 Apr 2024 14:27:11 +0200 Subject: [PATCH] Sorting files --- ui/arduino/views/components/file-list.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/arduino/views/components/file-list.js b/ui/arduino/views/components/file-list.js index 88de1b3..2767478 100644 --- a/ui/arduino/views/components/file-list.js +++ b/ui/arduino/views/components/file-list.js @@ -92,6 +92,18 @@ function generateFileList(source) { } // XXX: Use `source` to filter an array of files with a `source` as proprety + const files = state[`${source}Files`].sort((a, b) => { + const nameA = a.fileName.toUpperCase() + const nameB = b.fileName.toUpperCase() + // Folders come first than files + if (a.type === 'folder' && b.type === 'file') return -1 + // Folders and files come in alphabetic order + if (a.type === b.type) { + if (nameA < nameB) return -1 + if (nameA > nameB) return 1 + } + return 0 + }) const list = html`
@@ -103,7 +115,7 @@ function generateFileList(source) {
${state.creatingFile == source ? newFileItem : null} ${state.creatingFolder == source ? newFolderItem : null} - ${state[`${source}Files`].map(FileItem)} + ${files.map(FileItem)}
`