Merge pull request #49 from HaecheonLee/enh/open-note-in-tab-after-clicking-button

Open note in tab after clicking edit button
This commit is contained in:
1ilit 2024-04-15 05:19:45 +03:00 committed by GitHub
commit 89ccd61213
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 19 deletions

View File

@ -61,22 +61,18 @@ export default function Note({ data, onMouseDown }) {
}; };
const edit = () => { const edit = () => {
if (layout.sidebar) { setSelectedElement((prev) => ({
setSelectedElement((prev) => ({ ...prev,
...prev, ...(layout.sidebar && { currentTab: Tab.NOTES }),
currentTab: Tab.NOTES, ...(!layout.sidebar && { element: ObjectType.NOTE }),
})); id: data.id,
if (selectedElement.currentTab !== Tab.NOTES) return; open: true,
}));
if (layout.sidebar && selectedElement.currentTab === Tab.NOTES) {
document document
.getElementById(`scroll_note_${data.id}`) .getElementById(`scroll_note_${data.id}`)
.scrollIntoView({ behavior: "smooth" }); .scrollIntoView({ behavior: "smooth" });
} else {
setSelectedElement((prev) => ({
...prev,
element: ObjectType.NOTE,
id: data.id,
open: true,
}));
} }
}; };

View File

@ -1,20 +1,26 @@
import { useState } from "react";
import { Row, Col, Button, Collapse } from "@douyinfe/semi-ui"; import { Row, Col, Button, Collapse } from "@douyinfe/semi-ui";
import { IconPlus } from "@douyinfe/semi-icons"; import { IconPlus } from "@douyinfe/semi-icons";
import { useNotes } from "../../../hooks"; import { useNotes, useSelect } from "../../../hooks";
import Empty from "../Empty"; import Empty from "../Empty";
import SearchBar from "./SearchBar"; import SearchBar from "./SearchBar";
import NoteInfo from "./NoteInfo"; import NoteInfo from "./NoteInfo";
export default function NotesTab() { export default function NotesTab() {
const { notes, addNote } = useNotes(); const { notes, addNote } = useNotes();
const [activeKey, setActiveKey] = useState(""); const { selectedElement, setSelectedElement } = useSelect();
return ( return (
<> <>
<Row gutter={6}> <Row gutter={6}>
<Col span={16}> <Col span={16}>
<SearchBar setActiveKey={setActiveKey} /> <SearchBar
setActiveKey={(activeKey) =>
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
}))
}
/>
</Col> </Col>
<Col span={8}> <Col span={8}>
<Button icon={<IconPlus />} block onClick={() => addNote()}> <Button icon={<IconPlus />} block onClick={() => addNote()}>
@ -26,8 +32,14 @@ export default function NotesTab() {
<Empty title="No text notes" text="Add notes cuz why not!" /> <Empty title="No text notes" text="Add notes cuz why not!" />
) : ( ) : (
<Collapse <Collapse
activeKey={activeKey} activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
onChange={(k) => setActiveKey(k)} onChange={(activeKey) => {
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
open: true,
}));
}}
accordion accordion
> >
{notes.map((n, i) => ( {notes.map((n, i) => (