mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
chore(server/tree): improve type safety
This commit is contained in:
parent
864ac1a270
commit
a7a94789e6
@ -92,7 +92,10 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
|
||||
}
|
||||
|
||||
const notes = note.getChildNotes();
|
||||
const normalize = (obj: any) => (obj && typeof obj === "string" ? obj.toLowerCase() : obj);
|
||||
|
||||
function normalize<T>(obj: T | string) {
|
||||
return obj && typeof obj === "string" ? obj.toLowerCase() : obj;
|
||||
}
|
||||
|
||||
notes.sort((a, b) => {
|
||||
if (foldersFirst) {
|
||||
@ -106,7 +109,7 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
|
||||
}
|
||||
|
||||
function fetchValue(note: BNote, key: string) {
|
||||
let rawValue;
|
||||
let rawValue: string | null;
|
||||
|
||||
if (key === "title") {
|
||||
const branch = note.getParentBranches().find((branch) => branch.parentNoteId === parentNoteId);
|
||||
@ -151,15 +154,15 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
|
||||
return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1);
|
||||
}
|
||||
|
||||
const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title");
|
||||
const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title");
|
||||
const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title") as string;
|
||||
const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string;
|
||||
|
||||
if (customAEl !== customBEl) {
|
||||
return compare(customAEl, customBEl);
|
||||
}
|
||||
|
||||
const titleAEl = fetchValue(a, "title");
|
||||
const titleBEl = fetchValue(b, "title");
|
||||
const titleAEl = fetchValue(a, "title") as string;
|
||||
const titleBEl = fetchValue(b, "title") as string;
|
||||
|
||||
return compare(titleAEl, titleBEl);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user