From bcd27e10c1e29baa779b1109d14ddd4179e823a9 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 25 May 2023 15:52:26 +0500 Subject: [PATCH] web: add support for search inside notebook --- apps/web/src/components/search/index.js | 2 +- apps/web/src/views/search.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/search/index.js b/apps/web/src/components/search/index.js index c43360bc7..3a7646e3c 100644 --- a/apps/web/src/components/search/index.js +++ b/apps/web/src/components/search/index.js @@ -29,7 +29,7 @@ function SearchBox({ onSearch }) { id="search" name="search" type="text" - sx={{ m: 0, mx: 1, mt: 1 }} + sx={{ m: 0, mx: 2, mt: 1 }} placeholder="Type your query here" onChange={debounce((e) => onSearch(e.target.value), 250)} action={{ diff --git a/apps/web/src/views/search.js b/apps/web/src/views/search.js index 94e606b93..30976d6ba 100644 --- a/apps/web/src/views/search.js +++ b/apps/web/src/views/search.js @@ -31,6 +31,12 @@ import Placeholder from "../components/placeholders"; async function typeToItems(type, context) { switch (type) { + case "notebook": { + const selectedNotebook = notebookstore.get().selectedNotebook; + if (!selectedNotebook) return ["notes", []]; + const notes = db.relations.to(selectedNotebook, "note"); + return ["notes", notes]; + } case "notes": { await db.notes.init(); if (!context) return ["notes", db.notes.all]; @@ -113,11 +119,14 @@ function Search({ type }) { } case "notebooks": return "all notebooks"; + case "notebook": case "topics": { const selectedNotebook = notebookstore.get().selectedNotebook; if (!selectedNotebook) return ""; const notebook = db.notebooks.notebook(selectedNotebook.id); - return `topics in ${notebook.title} notebook`; + return `${type === "topics" ? "topics" : "notes"} in ${ + notebook.title + } notebook`; } case "tags": return "all tags";