chore(server/tree): improve type safety

This commit is contained in:
Elian Doran 2025-08-30 14:06:35 +03:00
parent 864ac1a270
commit a7a94789e6
No known key found for this signature in database

View File

@ -92,7 +92,10 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
} }
const notes = note.getChildNotes(); 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) => { notes.sort((a, b) => {
if (foldersFirst) { if (foldersFirst) {
@ -106,7 +109,7 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
} }
function fetchValue(note: BNote, key: string) { function fetchValue(note: BNote, key: string) {
let rawValue; let rawValue: string | null;
if (key === "title") { if (key === "title") {
const branch = note.getParentBranches().find((branch) => branch.parentNoteId === parentNoteId); 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); return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1);
} }
const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title"); const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title") as string;
const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title"); const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string;
if (customAEl !== customBEl) { if (customAEl !== customBEl) {
return compare(customAEl, customBEl); return compare(customAEl, customBEl);
} }
const titleAEl = fetchValue(a, "title"); const titleAEl = fetchValue(a, "title") as string;
const titleBEl = fetchValue(b, "title"); const titleBEl = fetchValue(b, "title") as string;
return compare(titleAEl, titleBEl); return compare(titleAEl, titleBEl);
}); });