Skip to content

Commit

Permalink
Merge pull request #49 from HaecheonLee/enh/open-note-in-tab-after-cl…
Browse files Browse the repository at this point in the history
…icking-button

Open note in tab after clicking edit button
  • Loading branch information
1ilit authored Apr 15, 2024
2 parents d95b085 + 157888f commit 89ccd61
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
22 changes: 9 additions & 13 deletions src/components/EditorCanvas/Note.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
}
};

Expand Down
24 changes: 18 additions & 6 deletions src/components/EditorSidePanel/NotesTab/NotesTab.jsx
Original file line number Diff line number Diff line change
@@ -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()}>
Expand All @@ -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) => (
Expand Down

0 comments on commit 89ccd61

Please sign in to comment.