Skip to content

Commit 7cfa26f

Browse files
authored
Merge pull request #106 from arduino/feature/file-sorting
Sorting files
2 parents d08ecaa + da87d75 commit 7cfa26f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ui/arduino/views/components/file-list.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ function generateFileList(source) {
9292
}
9393

9494
// XXX: Use `source` to filter an array of files with a `source` as proprety
95+
const files = state[`${source}Files`].sort((a, b) => {
96+
const nameA = a.fileName.toUpperCase()
97+
const nameB = b.fileName.toUpperCase()
98+
// Folders come first than files
99+
if (a.type === 'folder' && b.type === 'file') return -1
100+
// Folders and files come in alphabetic order
101+
if (a.type === b.type) {
102+
if (nameA < nameB) return -1
103+
if (nameA > nameB) return 1
104+
}
105+
return 0
106+
})
95107
const list = html`
96108
<div class="file-list">
97109
<div class="list">
@@ -103,7 +115,7 @@ function generateFileList(source) {
103115
</div>
104116
${state.creatingFile == source ? newFileItem : null}
105117
${state.creatingFolder == source ? newFolderItem : null}
106-
${state[`${source}Files`].map(FileItem)}
118+
${files.map(FileItem)}
107119
</div>
108120
</div>
109121
`

0 commit comments

Comments
 (0)