Added sidebar search functionality
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user