Skip to content

Commit

Permalink
Add new topic functionality and delete topic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
smallstone committed Jan 17, 2024
1 parent 4eb05d1 commit 378abec
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 43 deletions.
60 changes: 59 additions & 1 deletion src/util/ideaBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,32 @@ const JStoIdea = {

window.JSJavaBridge.callJava(JSON.stringify(params));
},
setNewTopic: () => {
const params = {
action: "loadConversations/request",
metadata: {
callback: "IdeaToJSMessage",
topicHash: "",
},
payload: {},
};

window.JSJavaBridge.callJava(JSON.stringify(params));
},
deleteTopic: (topicHash: string) => {
const params = {
action: "deleteTopic/request",
metadata: {
callback: "IdeaToJSMessage",
topicHash: topicHash,
},
payload: {
topicHash: topicHash,
},
};

window.JSJavaBridge.callJava(JSON.stringify(params));
},
historyMessages: (message) => {
const params = {
action: "loadHistoryMessages/request",
Expand Down Expand Up @@ -268,6 +294,28 @@ const JStoIdea = {
},
};

window.JSJavaBridge.callJava(JSON.stringify(params));
},
stopDevChat: () => {
const params = {
action: "stopGeneration/request",
metadata: {
callback: "IdeaToJSMessage",
},
payload: {},
};

window.JSJavaBridge.callJava(JSON.stringify(params));
},
regeneration: () => {
const params = {
action: "regeneration/request",
metadata: {
callback: "IdeaToJSMessage",
},
payload: {},
};

window.JSJavaBridge.callJava(JSON.stringify(params));
},
};
Expand Down Expand Up @@ -359,6 +407,7 @@ class IdeaBridge {
this.executeHandlers("reloadMessage", {
entries: list.reverse(),
pageIndex: 0,
reset: list.length === 0,
});
}

Expand Down Expand Up @@ -533,7 +582,7 @@ class IdeaBridge {
break;
// 重新生成消息,用于发送失败时再次发送
case "regeneration":
JStoIdea.sendMessage(message.text, message.context, message.parent);
JStoIdea.regeneration();
break;
// 请求 model 列表
case "regModelList":
Expand Down Expand Up @@ -587,6 +636,15 @@ class IdeaBridge {
case "setLanguage":
JStoIdea.setLanguage(message);
break;
case "setNewTopic":
JStoIdea.setNewTopic();
break;
case "deleteTopic":
JStoIdea.deleteTopic(message.topicHash);
break;
case "stopDevChat":
JStoIdea.stopDevChat();
break;
default:
break;
}
Expand Down
160 changes: 119 additions & 41 deletions src/views/components/InputMessage/Topic.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import React, { useEffect, useState } from "react";
import { ActionIcon, Drawer, Text, Box, Flex, Divider } from "@mantine/core";
import { IconClock, IconChevronDown } from "@tabler/icons-react";
import {
ActionIcon,
Drawer,
Text,
Box,
Flex,
Divider,
LoadingOverlay,
} from "@mantine/core";
import {
IconClock,
IconChevronDown,
IconPlus,
IconRefresh,
IconTrash,
} from "@tabler/icons-react";
import { useDisclosure } from "@mantine/hooks";
import messageUtil from "@/util/MessageUtil";
import dayjs from "dayjs";
import { t } from "mobx-state-tree";

export default function Topic({ styleName }) {
const [drawerOpened, { open: openDrawer, close: closeDrawer }] =
useDisclosure(false);
const [topicList, setTopicList] = useState([]);
const [loading, setLoading] = useState(false);
const [topicList, setTopicList] = useState<any>([]);

useEffect(() => {
messageUtil.sendMessage({
command: "listTopics",
});
messageUtil.registerHandler("listTopics", ({ list }: { list: any }) => {
setTopicList(list);
setLoading(false);
});
}, []);

Expand All @@ -27,12 +44,49 @@ export default function Topic({ styleName }) {
});
};

const refreshTopicList = () => {
setLoading(true);
messageUtil.sendMessage({
command: "listTopics",
});
};

const setNewTopic = () => {
messageUtil.sendMessage({
command: "setNewTopic",
});
closeDrawer();
};

const deleteTopic = (topicHash: string) => {
const newTopicList = topicList.filter(
(topic) => topic.root_prompt.hash !== topicHash
);
setTopicList(newTopicList);
messageUtil.sendMessage({
command: "deleteTopic",
topicHash: topicHash,
});
};

return (
<>
<Drawer
opened={drawerOpened}
position="bottom"
title="Devchat Topic"
title={
<Flex justify="space-between">
<Text>Devchat Topic</Text>
<Flex>
<ActionIcon onClick={setNewTopic}>
<IconPlus size="1rem" />
</ActionIcon>
<ActionIcon onClick={refreshTopicList}>
<IconRefresh size="1rem" />
</ActionIcon>
</Flex>
</Flex>
}
onClose={closeDrawer}
overlayProps={{ opacity: 0.5, blur: 4 }}
closeButtonProps={{ children: <IconChevronDown size="1rem" /> }}
Expand All @@ -46,57 +100,81 @@ export default function Topic({ styleName }) {
background: "var(--vscode-sideBar-background)",
color: "var(--vscode-editor-foreground)",
},
title: {
flex: 1,
},
}}
>
{topicList.map((item: any, index) => (
<Box
sx={{
cursor: "pointer",
}}
onClick={() => showTopic(item?.root_prompt)}
>
<Flex justify="space-between" gap="sm">
<Text
fz="sm"
fw={700}
<Box>
<Flex sx={{ width: "100%" }} gap="sm">
<Box
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
cursor: "pointer",
flex: 1,
}}
>
{item?.root_prompt.title}
</Text>
<Text
fz="sm"
c="dimmed"
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
onClick={() => showTopic(item?.root_prompt)}
>
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
</Text>
</Flex>
<Flex justify="space-between" gap="sm">
<Text
fz="sm"
fw={700}
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
flex: 1,
}}
>
{item?.root_prompt.title}
</Text>
<Text
fz="sm"
c="dimmed"
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
>
{dayjs(item?.latest_time * 1000).format("MM-DD HH:mm:ss")}
</Text>
</Flex>

<Text
c="dimmed"
fz="sm"
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
>
{item?.root_prompt.responses?.[0]}
</Text>
<Text
c="dimmed"
fz="sm"
sx={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
>
{item?.root_prompt.responses?.[0]}
</Text>
</Box>
<Flex align="center">
<ActionIcon
onClick={() => {
deleteTopic(item?.root_prompt.hash);
}}
>
<IconTrash size="1rem" />
</ActionIcon>
</Flex>
</Flex>
{index !== topicList.length - 1 && (
<Divider variant="solid" my={6} opacity="0.5" />
)}
</Box>
))}
<LoadingOverlay
visible={loading}
overlayBlur={3}
overlayOpacity={0}
keepMounted={true}
/>
</Drawer>
<ActionIcon
className={styleName}
Expand Down
5 changes: 4 additions & 1 deletion src/views/stores/ChatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Thinking...
self.isTop = false;
self.isBottom = false;
},
reloadMessage: ({ entries, pageIndex }) => {
reloadMessage: ({ entries, pageIndex, reset }) => {
if (entries.length > 0) {
self.pageIndex = pageIndex;
const messages = entries
Expand Down Expand Up @@ -401,6 +401,9 @@ Thinking...
}
} else {
self.isLastPage = true;
if (reset) {
self.messages = [] as any;
}
if (self.messages.length === 0) {
helpMessage(true);
}
Expand Down

0 comments on commit 378abec

Please sign in to comment.