Skip to content

Commit 7f32fd5

Browse files
authored
Merge pull request #19 from devchat-ai/feat/topic
Refactor Topic component and fix useEffect dependency
2 parents de0580b + bc61014 commit 7f32fd5

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/views/components/InputMessage/Topic.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
import { useDisclosure } from "@mantine/hooks";
1919
import messageUtil from "@/util/MessageUtil";
2020
import dayjs from "dayjs";
21-
import { t } from "mobx-state-tree";
2221

2322
export default function Topic({ styleName }) {
2423
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
@@ -27,15 +26,20 @@ export default function Topic({ styleName }) {
2726
const [topicList, setTopicList] = useState<any>([]);
2827

2928
useEffect(() => {
30-
messageUtil.sendMessage({
31-
command: "listTopics",
32-
});
3329
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
3430
setTopicList(list);
3531
setLoading(false);
3632
});
3733
}, []);
3834

35+
useEffect(() => {
36+
if (drawerOpened) {
37+
messageUtil.sendMessage({
38+
command: "listTopics",
39+
});
40+
}
41+
}, [drawerOpened]);
42+
3943
const showTopic = (root_prompt: any) => {
4044
closeDrawer();
4145
messageUtil.sendMessage({

0 commit comments

Comments
 (0)