Adds notes.

This commit is contained in:
2026-04-21 15:39:16 -07:00
parent 1e5d1f13e8
commit 81c912e3ff
14 changed files with 1525 additions and 830 deletions

37
src/lib/hierarchy.ts Normal file
View File

@@ -0,0 +1,37 @@
export interface HierarchyNode {
id: string | null;
title: string | null;
children: Hierarchy | null;
}
export interface Hierarchy extends Record<string, HierarchyNode> {}
function addToHierarchy(
tree: Hierarchy,
[noteId, title]: [string, string],
): Hierarchy {
const path = noteId.split("/");
if (path.length === 0) {
return tree;
}
if (!tree[path[0]]) {
tree[path[0]] = { id: null, title: null, children: null };
}
let curr = tree[path[0]];
for (const node of path.slice(1)) {
curr.children ||= {};
if (!curr.children[node]) {
curr.children[node] = { id: null, title: null, children: null };
}
curr = curr.children[node];
}
curr.id = noteId;
curr.title = title;
return tree;
}
export function makeHierarchy(notes: Array<[string, string]>): Hierarchy {
return notes.reduce(addToHierarchy, {});
}