mirror of
https://github.com/VueTorrent/VueTorrent.git
synced 2024-11-28 21:18:54 +03:00
perf: Sort folders before files (#730)
This commit is contained in:
parent
7d6edfc9d9
commit
521c6e6c7f
2 changed files with 10 additions and 2 deletions
|
@ -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}`,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue