web: lookup topic notes at notebook level

This commit is contained in:
ammarahm-ed
2023-06-16 12:11:24 +05:00
committed by Abdullah Atta
parent fb7b306bc5
commit 0a45e963a6
2 changed files with 18 additions and 2 deletions

View File

@@ -65,7 +65,7 @@ const routes = {
return {
key: "notebook",
type: "notebook",
type: "notes",
component: <Topics />,
buttons: {
back: {

View File

@@ -41,7 +41,19 @@ async function typeToItems(type, context) {
await db.notes.init();
if (!context) return ["notes", db.notes.all];
const notes = context.notes;
return ["notes", notes];
let topicNotes = [];
if (context.type === "notebook") {
topicNotes = db.notebooks
.notebook(context.value.id)
.topics.all.map((topic) => {
return db.notes.topicReferences
.get(topic.id)
.map((id) => db.notes.note(id).data);
})
.flat()
.filter((n) => notes.findIndex((note) => note.id !== n.id) === -1);
}
return ["notes", [...notes, ...topicNotes]];
}
case "notebooks":
return ["notebooks", db.notebooks.all];
@@ -105,6 +117,10 @@ function Search({ type }) {
const topic = notebook.topics.topic(context.value.topic);
return `notes of ${topic._topic.title} in ${notebook.title}`;
}
case "notebook": {
const notebook = db.notebooks.notebook(context.value.id);
return `notes in ${notebook.title}`;
}
case "tag": {
const tag = db.tags.all.find((tag) => tag.id === context.value);
return `notes in #${tag.title}`;