import { useState } from "react"; import { Empty, Row, Col, Button, Collapse, AutoComplete, TextArea, Popover, Input, Toast, } from "@douyinfe/semi-ui"; import { IllustrationNoContent, IllustrationNoContentDark, } from "@douyinfe/semi-illustrations"; import { IconDeleteStroked, IconPlus, IconSearch, IconCheckboxTick, } from "@douyinfe/semi-icons"; import { noteThemes, Action, ObjectType } from "../data/data"; import useUndoRedo from "../hooks/useUndoRedo"; import useNotes from "../hooks/useNotes"; export default function NotesOverview() { const { notes, updateNote, addNote, deleteNote } = useNotes(); const { setUndoStack, setRedoStack } = useUndoRedo(); const [value, setValue] = useState(""); const [editField, setEditField] = useState({}); const [activeKey, setActiveKey] = useState(""); const [filteredResult, setFilteredResult] = useState( notes.map((t) => { return t.title; }) ); const handleStringSearch = (value) => { setFilteredResult( notes .map((t) => { return t.title; }) .filter((i) => i.includes(value)) ); }; return (
} placeholder="Search..." emptyContent={
No notes found
} onSearch={(v) => handleStringSearch(v)} onChange={(v) => setValue(v)} onSelect={(v) => { const { id } = notes.find((t) => t.title === v); setActiveKey(`${id}`); document .getElementById(`scroll_note_${id}`) .scrollIntoView({ behavior: "smooth" }); }} className="w-full" />
{notes.length <= 0 ? (
} darkModeImage={ } title="No text notes" description="Add notes cuz why not!" />
) : ( setActiveKey(k)} accordion > {notes.map((n, i) => ( {n.title}
} itemKey={`${n.id}`} id={`scroll_note_${n.id}`} key={n.id} >
Title:
updateNote(n.id, { title: value })} onFocus={(e) => setEditField({ title: e.target.value })} onBlur={(e) => { if (e.target.value === editField.title) return; setUndoStack((prev) => [ ...prev, { action: Action.EDIT, element: ObjectType.NOTE, nid: n.id, undo: editField, redo: { title: e.target.value }, message: `Edit note title to "${e.target.name}"`, }, ]); setRedoStack([]); }} />