Skip to content

Commit 4424173

Browse files
authored
Merge pull request #52 from HaecheonLee/enh/open-note-when-note-title-is-clicked-in-search-in-note-tab
Open note when a note's title is clicked in search in note tab
2 parents 4cfd91d + d545d14 commit 4424173

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/components/EditorSidePanel/TypesTab/SearchBar.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { useState } from "react";
22
import { AutoComplete } from "@douyinfe/semi-ui";
33
import { IconSearch } from "@douyinfe/semi-icons";
4-
import { useTypes } from "../../../hooks";
4+
import { useSelect, useTypes } from "../../../hooks";
55

66
export default function Searchbar() {
77
const { types } = useTypes();
88
const [value, setValue] = useState("");
9+
const { setSelectedElement } = useSelect();
910

1011
const [filteredResult, setFilteredResult] = useState(
11-
types.map((t) => t.name)
12+
types.map((t) => t.name),
1213
);
1314

1415
const handleStringSearch = (value) => {
1516
setFilteredResult(
16-
types.map((t) => t.name).filter((i) => i.includes(value))
17+
types.map((t) => t.name).filter((i) => i.includes(value)),
1718
);
1819
};
1920

@@ -29,6 +30,11 @@ export default function Searchbar() {
2930
onChange={(v) => setValue(v)}
3031
onSelect={(v) => {
3132
const i = types.findIndex((t) => t.name === v);
33+
setSelectedElement((prev) => ({
34+
...prev,
35+
id: parseInt(i),
36+
open: true,
37+
}));
3238
document
3339
.getElementById(`scroll_type_${i}`)
3440
.scrollIntoView({ behavior: "smooth" });

src/components/EditorSidePanel/TypesTab/TypesTab.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Collapse, Row, Col, Button, Popover } from "@douyinfe/semi-ui";
22
import { IconPlus, IconInfoCircle } from "@douyinfe/semi-icons";
33
import Searchbar from "./SearchBar";
44
import Empty from "../Empty";
5-
import { useTypes } from "../../../hooks";
5+
import { useSelect, useTypes } from "../../../hooks";
66
import TypeInfo from "./TypeInfo";
77

88
export default function TypesTab() {
99
const { types, addType } = useTypes();
10+
const { selectedElement, setSelectedElement } = useSelect();
1011

1112
return (
1213
<>
@@ -52,7 +53,17 @@ export default function TypesTab() {
5253
{types.length <= 0 ? (
5354
<Empty title="No types" text="Make your own custom data types" />
5455
) : (
55-
<Collapse accordion>
56+
<Collapse
57+
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
58+
onChange={(id) =>
59+
setSelectedElement((prev) => ({
60+
...prev,
61+
id: parseInt(id),
62+
open: true,
63+
}))
64+
}
65+
accordion
66+
>
5667
{types.map((t, i) => (
5768
<TypeInfo data={t} key={i} index={i} />
5869
))}

0 commit comments

Comments
 (0)