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 = () => {
if (layout.sidebar) {
setSelectedElement((prev) => ({
...prev,
currentTab: Tab.NOTES,
}));
if (selectedElement.currentTab !== Tab.NOTES) return;
setSelectedElement((prev) => ({
...prev,
...(layout.sidebar && { currentTab: Tab.NOTES }),
...(!layout.sidebar && { element: ObjectType.NOTE }),
id: data.id,
open: true,
}));
if (layout.sidebar && selectedElement.currentTab === Tab.NOTES) {
document
.getElementById(`scroll_note_${data.id}`)
.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 { IconPlus } from "@douyinfe/semi-icons";
import { useNotes } from "../../../hooks";
import { useNotes, useSelect } from "../../../hooks";
import Empty from "../Empty";
import SearchBar from "./SearchBar";
import NoteInfo from "./NoteInfo";
export default function NotesTab() {
const { notes, addNote } = useNotes();
const [activeKey, setActiveKey] = useState("");
const { selectedElement, setSelectedElement } = useSelect();
return (
<>
<Row gutter={6}>
<Col span={16}>
<SearchBar setActiveKey={setActiveKey} />
<SearchBar
setActiveKey={(activeKey) =>
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
}))
}
/>
</Col>
<Col span={8}>
<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!" />
) : (
<Collapse
activeKey={activeKey}
onChange={(k) => setActiveKey(k)}
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
onChange={(activeKey) => {
setSelectedElement((prev) => ({
...prev,
id: parseInt(activeKey),
open: true,
}));
}}
accordion
>
{notes.map((n, i) => (