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
This commit is contained in:
commit
4424173a10
@ -1,19 +1,20 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { AutoComplete } from "@douyinfe/semi-ui";
|
import { AutoComplete } from "@douyinfe/semi-ui";
|
||||||
import { IconSearch } from "@douyinfe/semi-icons";
|
import { IconSearch } from "@douyinfe/semi-icons";
|
||||||
import { useTypes } from "../../../hooks";
|
import { useSelect, useTypes } from "../../../hooks";
|
||||||
|
|
||||||
export default function Searchbar() {
|
export default function Searchbar() {
|
||||||
const { types } = useTypes();
|
const { types } = useTypes();
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
|
const { setSelectedElement } = useSelect();
|
||||||
|
|
||||||
const [filteredResult, setFilteredResult] = useState(
|
const [filteredResult, setFilteredResult] = useState(
|
||||||
types.map((t) => t.name)
|
types.map((t) => t.name),
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleStringSearch = (value) => {
|
const handleStringSearch = (value) => {
|
||||||
setFilteredResult(
|
setFilteredResult(
|
||||||
types.map((t) => t.name).filter((i) => i.includes(value))
|
types.map((t) => t.name).filter((i) => i.includes(value)),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,6 +30,11 @@ export default function Searchbar() {
|
|||||||
onChange={(v) => setValue(v)}
|
onChange={(v) => setValue(v)}
|
||||||
onSelect={(v) => {
|
onSelect={(v) => {
|
||||||
const i = types.findIndex((t) => t.name === v);
|
const i = types.findIndex((t) => t.name === v);
|
||||||
|
setSelectedElement((prev) => ({
|
||||||
|
...prev,
|
||||||
|
id: parseInt(i),
|
||||||
|
open: true,
|
||||||
|
}));
|
||||||
document
|
document
|
||||||
.getElementById(`scroll_type_${i}`)
|
.getElementById(`scroll_type_${i}`)
|
||||||
.scrollIntoView({ behavior: "smooth" });
|
.scrollIntoView({ behavior: "smooth" });
|
||||||
|
@ -2,11 +2,12 @@ import { Collapse, Row, Col, Button, Popover } from "@douyinfe/semi-ui";
|
|||||||
import { IconPlus, IconInfoCircle } from "@douyinfe/semi-icons";
|
import { IconPlus, IconInfoCircle } from "@douyinfe/semi-icons";
|
||||||
import Searchbar from "./SearchBar";
|
import Searchbar from "./SearchBar";
|
||||||
import Empty from "../Empty";
|
import Empty from "../Empty";
|
||||||
import { useTypes } from "../../../hooks";
|
import { useSelect, useTypes } from "../../../hooks";
|
||||||
import TypeInfo from "./TypeInfo";
|
import TypeInfo from "./TypeInfo";
|
||||||
|
|
||||||
export default function TypesTab() {
|
export default function TypesTab() {
|
||||||
const { types, addType } = useTypes();
|
const { types, addType } = useTypes();
|
||||||
|
const { selectedElement, setSelectedElement } = useSelect();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -52,7 +53,17 @@ export default function TypesTab() {
|
|||||||
{types.length <= 0 ? (
|
{types.length <= 0 ? (
|
||||||
<Empty title="No types" text="Make your own custom data types" />
|
<Empty title="No types" text="Make your own custom data types" />
|
||||||
) : (
|
) : (
|
||||||
<Collapse accordion>
|
<Collapse
|
||||||
|
activeKey={selectedElement.open ? `${selectedElement.id}` : ""}
|
||||||
|
onChange={(id) =>
|
||||||
|
setSelectedElement((prev) => ({
|
||||||
|
...prev,
|
||||||
|
id: parseInt(id),
|
||||||
|
open: true,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
accordion
|
||||||
|
>
|
||||||
{types.map((t, i) => (
|
{types.map((t, i) => (
|
||||||
<TypeInfo data={t} key={i} index={i} />
|
<TypeInfo data={t} key={i} index={i} />
|
||||||
))}
|
))}
|
||||||
|
Loading…
Reference in New Issue
Block a user