drawDB/src/components/EditorSidePanel/NotesTab/NotesTab.jsx

54 lines
1.4 KiB
React
Raw Normal View History

2024-04-06 09:58:42 +08:00
import { useState } from "react";
import { Row, Col, Button, Collapse } from "@douyinfe/semi-ui";
import { IconPlus } from "@douyinfe/semi-icons";
import { useNotes, useSelect } from "../../../hooks";
2024-04-06 09:58:42 +08:00
import Empty from "../Empty";
import SearchBar from "./SearchBar";
import NoteInfo from "./NoteInfo";
export default function NotesTab() {
const { notes, addNote } = useNotes();
const { selectedElement, setSelectedElement } = useSelect();
2024-04-06 09:58:42 +08:00
return (
<>
<Row gutter={6}>
<Col span={16}>
<SearchBar
setActiveKey={(activeKey) =>
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
}))
}
/>
2024-04-06 09:58:42 +08:00
</Col>
<Col span={8}>
<Button icon={<IconPlus />} block onClick={() => addNote()}>
Add note
</Button>
</Col>
</Row>
{notes.length <= 0 ? (
<Empty title="No text notes" text="Add notes cuz why not!" />
) : (
<Collapse
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
onChange={(activeKey) => {
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
open: true,
}));
}}
2024-04-06 09:58:42 +08:00
accordion
>
{notes.map((n, i) => (
<NoteInfo data={n} key={i} nid={i} />
))}
</Collapse>
)}
</>
);
}