Refactor Topic component and fix useEffect dependency

This commit is contained in:
smallstone 2024-01-17 20:45:47 +08:00
parent 556c589050
commit bc61014e98

View File

@ -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({