1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-12-05 22:57:29 +02:00

Desktop: Fixes #3052: Fixed order of notebooks in "Move to notebook" dialog (#3084)

* Added Folder::sortFolderTree

* Added unit tests
This commit is contained in:
Siddhant Sehgal
2020-05-09 20:49:30 +05:30
committed by GitHub
parent 3b653a95a0
commit 0f8f7aeb14
3 changed files with 50 additions and 2 deletions

View File

@@ -323,6 +323,33 @@ class Folder extends BaseItem {
return rootFolders;
}
static async sortFolderTree(folders) {
const output = folders ? folders : await this.allAsTree();
const sortFoldersAlphabetically = (folders) => {
folders.sort((a, b) => {
if (a.parentId === b.parentId) {
return a.title.localeCompare(b.title, undefined, { sensitivity: 'accent' });
}
});
return folders;
};
const sortFolders = (folders) => {
for (let i = 0; i < folders.length; i++) {
const folder = folders[i];
if (folder.children) {
folder.children = sortFoldersAlphabetically(folder.children);
sortFolders(folder.children);
}
}
return folders;
};
sortFolders(sortFoldersAlphabetically(output));
return output;
}
static load(id) {
if (id == this.conflictFolderId()) return this.conflictFolder();
return super.load(id);