Added sidebar search functionality

This commit is contained in:
2026-01-23 12:05:30 +00:00
parent b5ac1df4e3
commit 211dbb72e0

View File

@@ -10,16 +10,18 @@ import ListItem from "./ListItem"
import { useNote } from "../contexts/ActiveNoteContext" import { useNote } from "../contexts/ActiveNoteContext"
import { useNotesStore } from "../contexts/NotesStore" import { useNotesStore } from "../contexts/NotesStore"
import { useTheme } from "../contexts/ThemeContext" import { useTheme } from "../contexts/ThemeContext"
import { ReactNode } from "react" import { ChangeEvent, ReactNode, useState } from "react"
function AppSidebar() { function AppSidebar() {
const { notes, createNote } = useNotesStore() const { notes, createNote } = useNotesStore()
const { setCurrentNoteId } = useNote() const { setCurrentNoteId } = useNote()
const { theme, toggleTheme } = useTheme() const { theme, toggleTheme } = useTheme()
const [ filter, setFilter ] = useState("")
const buildNoteListItems = () => { const buildNoteListItems = () => {
const out: ReactNode[] = [] const out: ReactNode[] = []
notes.forEach((note, key, _) => { notes.forEach((note, key, _) => {
if (filter && !note.title.toLowerCase().includes(filter.toLowerCase())) return;
out.push( out.push(
<ListItem <ListItem
key={key} key={key}
@@ -42,7 +44,11 @@ function AppSidebar() {
{theme === "dark" ? <Sun /> : <Moon />} {theme === "dark" ? <Sun /> : <Moon />}
</Button> </Button>
</div> </div>
<Input placeholder="Search Notes" className="shadow-none bg-background" /> <Input
placeholder="Search Notes"
className="shadow-none bg-background"
onChange={(e) => setFilter(e.target.value)}
/>
</SidebarHeader> </SidebarHeader>
<SidebarContent> <SidebarContent>