perf: Sort folders before files (#730)

This commit is contained in:
Rémi Marseault 2023-03-22 09:53:44 +01:00 committed by GitHub
parent 7d6edfc9d9
commit 521c6e6c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -100,12 +100,18 @@ function createFile(data, name, children) {
size: formatBytes(data.size),
icon: getIconForFileType(name.split('.').pop()),
priority: data.priority,
children: children
children: children,
type: 'file'
}
}
function createFolder(parent, name, children) {
children.sort((a, b) => a.name.localeCompare(b.name))
children.sort((a, b) => {
if (a.type === b.type) return a.name.localeCompare(b.name)
else if (a.type === 'directory') return -1
else return 1
})
return {
name: name,
fullName: parent === undefined ? name : `${parent.fullName}/${name}`,

View file

@ -2,6 +2,7 @@ export interface TreeNode {
name: string
fullName: string
children: TreeNode[]
type: 'file' | 'directory'
}
export interface TreeFile extends TreeNode {
@ -10,6 +11,7 @@ export interface TreeFile extends TreeNode {
size: string
icon: string
priority: number
type: 'file'
}
export interface TreeFolder extends TreeNode {