web: add support for search inside notebook

This commit is contained in:
Abdullah Atta
2023-05-25 15:52:26 +05:00
committed by Abdullah Atta
parent af9b9b7083
commit bcd27e10c1
2 changed files with 11 additions and 2 deletions

View File

@@ -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={{

View File

@@ -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";