Refactor Topic component and fix useEffect dependency
This commit is contained in:
parent
556c589050
commit
bc61014e98
@ -18,7 +18,6 @@ import {
|
|||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure } from "@mantine/hooks";
|
||||||
import messageUtil from "@/util/MessageUtil";
|
import messageUtil from "@/util/MessageUtil";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { t } from "mobx-state-tree";
|
|
||||||
|
|
||||||
export default function Topic({ styleName }) {
|
export default function Topic({ styleName }) {
|
||||||
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
|
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
|
||||||
@ -27,15 +26,20 @@ export default function Topic({ styleName }) {
|
|||||||
const [topicList, setTopicList] = useState<any>([]);
|
const [topicList, setTopicList] = useState<any>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
messageUtil.sendMessage({
|
|
||||||
command: "listTopics",
|
|
||||||
});
|
|
||||||
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
|
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
|
||||||
setTopicList(list);
|
setTopicList(list);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (drawerOpened) {
|
||||||
|
messageUtil.sendMessage({
|
||||||
|
command: "listTopics",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [drawerOpened]);
|
||||||
|
|
||||||
const showTopic = (root_prompt: any) => {
|
const showTopic = (root_prompt: any) => {
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
messageUtil.sendMessage({
|
messageUtil.sendMessage({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user