Skip to content

Commit 378abec

Browse files
author
smallstone
committed
Add new topic functionality and delete topic functionality
1 parent 4eb05d1 commit 378abec

File tree

3 files changed

+182
-43
lines changed

3 files changed

+182
-43
lines changed

src/util/ideaBridge.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,32 @@ const JStoIdea = {
202202

203203
window.JSJavaBridge.callJava(JSON.stringify(params));
204204
},
205+
setNewTopic: () => {
206+
const params = {
207+
action: "loadConversations/request",
208+
metadata: {
209+
callback: "IdeaToJSMessage",
210+
topicHash: "",
211+
},
212+
payload: {},
213+
};
214+
215+
window.JSJavaBridge.callJava(JSON.stringify(params));
216+
},
217+
deleteTopic: (topicHash: string) => {
218+
const params = {
219+
action: "deleteTopic/request",
220+
metadata: {
221+
callback: "IdeaToJSMessage",
222+
topicHash: topicHash,
223+
},
224+
payload: {
225+
topicHash: topicHash,
226+
},
227+
};
228+
229+
window.JSJavaBridge.callJava(JSON.stringify(params));
230+
},
205231
historyMessages: (message) => {
206232
const params = {
207233
action: "loadHistoryMessages/request",
@@ -268,6 +294,28 @@ const JStoIdea = {
268294
},
269295
};
270296

297+
window.JSJavaBridge.callJava(JSON.stringify(params));
298+
},
299+
stopDevChat: () => {
300+
const params = {
301+
action: "stopGeneration/request",
302+
metadata: {
303+
callback: "IdeaToJSMessage",
304+
},
305+
payload: {},
306+
};
307+
308+
window.JSJavaBridge.callJava(JSON.stringify(params));
309+
},
310+
regeneration: () => {
311+
const params = {
312+
action: "regeneration/request",
313+
metadata: {
314+
callback: "IdeaToJSMessage",
315+
},
316+
payload: {},
317+
};
318+
271319
window.JSJavaBridge.callJava(JSON.stringify(params));
272320
},
273321
};
@@ -359,6 +407,7 @@ class IdeaBridge {
359407
this.executeHandlers("reloadMessage", {
360408
entries: list.reverse(),
361409
pageIndex: 0,
410+
reset: list.length === 0,
362411
});
363412
}
364413

@@ -533,7 +582,7 @@ class IdeaBridge {
533582
break;
534583
// 重新生成消息,用于发送失败时再次发送
535584
case "regeneration":
536-
JStoIdea.sendMessage(message.text, message.context, message.parent);
585+
JStoIdea.regeneration();
537586
break;
538587
// 请求 model 列表
539588
case "regModelList":
@@ -587,6 +636,15 @@ class IdeaBridge {
587636
case "setLanguage":
588637
JStoIdea.setLanguage(message);
589638
break;
639+
case "setNewTopic":
640+
JStoIdea.setNewTopic();
641+
break;
642+
case "deleteTopic":
643+
JStoIdea.deleteTopic(message.topicHash);
644+
break;
645+
case "stopDevChat":
646+
JStoIdea.stopDevChat();
647+
break;
590648
default:
591649
break;
592650
}

src/views/components/InputMessage/Topic.tsx

Lines changed: 119 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
import React, { useEffect, useState } from "react";
2-
import { ActionIcon, Drawer, Text, Box, Flex, Divider } from "@mantine/core";
3-
import { IconClock, IconChevronDown } from "@tabler/icons-react";
2+
import {
3+
ActionIcon,
4+
Drawer,
5+
Text,
6+
Box,
7+
Flex,
8+
Divider,
9+
LoadingOverlay,
10+
} from "@mantine/core";
11+
import {
12+
IconClock,
13+
IconChevronDown,
14+
IconPlus,
15+
IconRefresh,
16+
IconTrash,
17+
} from "@tabler/icons-react";
418
import { useDisclosure } from "@mantine/hooks";
519
import messageUtil from "@/util/MessageUtil";
620
import dayjs from "dayjs";
21+
import { t } from "mobx-state-tree";
722

823
export default function Topic({ styleName }) {
924
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
1025
useDisclosure(false);
11-
const [topicList, setTopicList] = useState([]);
26+
const [loading, setLoading] = useState(false);
27+
const [topicList, setTopicList] = useState<any>([]);
1228

1329
useEffect(() => {
1430
messageUtil.sendMessage({
1531
command: "listTopics",
1632
});
1733
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
1834
setTopicList(list);
35+
setLoading(false);
1936
});
2037
}, []);
2138

@@ -27,12 +44,49 @@ export default function Topic({ styleName }) {
2744
});
2845
};
2946

47+
const refreshTopicList = () => {
48+
setLoading(true);
49+
messageUtil.sendMessage({
50+
command: "listTopics",
51+
});
52+
};
53+
54+
const setNewTopic = () => {
55+
messageUtil.sendMessage({
56+
command: "setNewTopic",
57+
});
58+
closeDrawer();
59+
};
60+
61+
const deleteTopic = (topicHash: string) => {
62+
const newTopicList = topicList.filter(
63+
(topic) => topic.root_prompt.hash !== topicHash
64+
);
65+
setTopicList(newTopicList);
66+
messageUtil.sendMessage({
67+
command: "deleteTopic",
68+
topicHash: topicHash,
69+
});
70+
};
71+
3072
return (
3173
<>
3274
<Drawer
3375
opened={drawerOpened}
3476
position="bottom"
35-
title="Devchat Topic"
77+
title={
78+
<Flex justify="space-between">
79+
<Text>Devchat Topic</Text>
80+
<Flex>
81+
<ActionIcon onClick={setNewTopic}>
82+
<IconPlus size="1rem" />
83+
</ActionIcon>
84+
<ActionIcon onClick={refreshTopicList}>
85+
<IconRefresh size="1rem" />
86+
</ActionIcon>
87+
</Flex>
88+
</Flex>
89+
}
3690
onClose={closeDrawer}
3791
overlayProps={{ opacity: 0.5, blur: 4 }}
3892
closeButtonProps={{ children: <IconChevronDown size="1rem" /> }}
@@ -46,57 +100,81 @@ export default function Topic({ styleName }) {
46100
background: "var(--vscode-sideBar-background)",
47101
color: "var(--vscode-editor-foreground)",
48102
},
103+
title: {
104+
flex: 1,
105+
},
49106
}}
50107
>
51108
{topicList.map((item: any, index) => (
52-
<Box
53-
sx={{
54-
cursor: "pointer",
55-
}}
56-
onClick={() => showTopic(item?.root_prompt)}
57-
>
58-
<Flex justify="space-between" gap="sm">
59-
<Text
60-
fz="sm"
61-
fw={700}
109+
<Box>
110+
<Flex sx={{ width: "100%" }} gap="sm">
111+
<Box
62112
sx={{
63-
whiteSpace: "nowrap",
64-
overflow: "hidden",
65-
textOverflow: "ellipsis",
113+
cursor: "pointer",
66114
flex: 1,
67-
}}
68-
>
69-
{item?.root_prompt.title}
70-
</Text>
71-
<Text
72-
fz="sm"
73-
c="dimmed"
74-
sx={{
75-
whiteSpace: "nowrap",
76115
overflow: "hidden",
77-
textOverflow: "ellipsis",
78116
}}
117+
onClick={() => showTopic(item?.root_prompt)}
79118
>
80-
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
81-
</Text>
82-
</Flex>
119+
<Flex justify="space-between" gap="sm">
120+
<Text
121+
fz="sm"
122+
fw={700}
123+
sx={{
124+
whiteSpace: "nowrap",
125+
overflow: "hidden",
126+
textOverflow: "ellipsis",
127+
flex: 1,
128+
}}
129+
>
130+
{item?.root_prompt.title}
131+
</Text>
132+
<Text
133+
fz="sm"
134+
c="dimmed"
135+
sx={{
136+
whiteSpace: "nowrap",
137+
overflow: "hidden",
138+
textOverflow: "ellipsis",
139+
}}
140+
>
141+
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
142+
</Text>
143+
</Flex>
83144

84-
<Text
85-
c="dimmed"
86-
fz="sm"
87-
sx={{
88-
whiteSpace: "nowrap",
89-
overflow: "hidden",
90-
textOverflow: "ellipsis",
91-
}}
92-
>
93-
{item?.root_prompt.responses?.[0]}
94-
</Text>
145+
<Text
146+
c="dimmed"
147+
fz="sm"
148+
sx={{
149+
whiteSpace: "nowrap",
150+
overflow: "hidden",
151+
textOverflow: "ellipsis",
152+
}}
153+
>
154+
{item?.root_prompt.responses?.[0]}
155+
</Text>
156+
</Box>
157+
<Flex align="center">
158+
<ActionIcon
159+
onClick={() => {
160+
deleteTopic(item?.root_prompt.hash);
161+
}}
162+
>
163+
<IconTrash size="1rem" />
164+
</ActionIcon>
165+
</Flex>
166+
</Flex>
95167
{index !== topicList.length - 1 && (
96168
<Divider variant="solid" my={6} opacity="0.5" />
97169
)}
98170
</Box>
99171
))}
172+
<LoadingOverlay
173+
visible={loading}
174+
overlayBlur={3}
175+
overlayOpacity={0}
176+
keepMounted={true}
177+
/>
100178
</Drawer>
101179
<ActionIcon
102180
className={styleName}

src/views/stores/ChatStore.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Thinking...
373373
self.isTop = false;
374374
self.isBottom = false;
375375
},
376-
reloadMessage: ({ entries, pageIndex }) => {
376+
reloadMessage: ({ entries, pageIndex, reset }) => {
377377
if (entries.length > 0) {
378378
self.pageIndex = pageIndex;
379379
const messages = entries
@@ -401,6 +401,9 @@ Thinking...
401401
}
402402
} else {
403403
self.isLastPage = true;
404+
if (reset) {
405+
self.messages = [] as any;
406+
}
404407
if (self.messages.length === 0) {
405408
helpMessage(true);
406409
}

0 commit comments

Comments
 (0)