diff --git a/src/renderer/src/hooks/useAssistant.ts b/src/renderer/src/hooks/useAssistant.ts index 77bea1cb..0c3a5a4c 100644 --- a/src/renderer/src/hooks/useAssistant.ts +++ b/src/renderer/src/hooks/useAssistant.ts @@ -49,6 +49,10 @@ export function useAssistant(id: string) { TopicManager.removeTopic(topic.id) dispatch(removeTopic({ assistantId: assistant.id, topic })) }, + moveTopic: (topic: Topic, toAssistant: Assistant) => { + dispatch(addTopic({ assistantId: toAssistant.id, topic: { ...topic } })) + dispatch(removeTopic({ assistantId: assistant.id, topic })) + }, updateTopic: (topic: Topic) => dispatch(updateTopic({ assistantId: assistant.id, topic })), updateTopics: (topics: Topic[]) => dispatch(updateTopics({ assistantId: assistant.id, topics })), removeAllTopics: () => dispatch(removeAllTopics({ assistantId: assistant.id })), diff --git a/src/renderer/src/i18n/index.ts b/src/renderer/src/i18n/index.ts index 7c5eb3e7..51c6bfe3 100644 --- a/src/renderer/src/i18n/index.ts +++ b/src/renderer/src/i18n/index.ts @@ -70,10 +70,11 @@ const resources = { 'default.topic.name': 'Default Topic', 'topics.title': 'Topics', 'topics.auto_rename': 'Auto Rename', - 'topics.edit.title': 'Rename', + 'topics.edit.title': 'Edit Name', 'topics.edit.placeholder': 'Enter new name', 'topics.delete.all.title': 'Delete all topics', 'topics.delete.all.content': 'Are you sure you want to delete all topics?', + 'topics.move_to': 'Move to', 'topics.list': 'Topic List', 'input.new_topic': 'New Topic', 'input.topics': ' Topics ', @@ -341,6 +342,7 @@ const resources = { 'topics.edit.placeholder': '输入新名称', 'topics.delete.all.title': '删除所有话题', 'topics.delete.all.content': '确定要删除所有话题吗?', + 'topics.move_to': '移动到', 'topics.list': '话题列表', 'input.new_topic': '新话题', 'input.topics': ' 话题 ', diff --git a/src/renderer/src/pages/home/Topics.tsx b/src/renderer/src/pages/home/Topics.tsx index 2f4f641b..167c0e4c 100644 --- a/src/renderer/src/pages/home/Topics.tsx +++ b/src/renderer/src/pages/home/Topics.tsx @@ -1,7 +1,7 @@ -import { CloseOutlined, DeleteOutlined, EditOutlined, OpenAIOutlined } from '@ant-design/icons' +import { CloseOutlined, DeleteOutlined, EditOutlined, FolderOutlined } from '@ant-design/icons' import DragableList from '@renderer/components/DragableList' import PromptPopup from '@renderer/components/Popups/PromptPopup' -import { useAssistant } from '@renderer/hooks/useAssistant' +import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant' import { TopicManager } from '@renderer/hooks/useTopic' import { fetchMessagesSummary } from '@renderer/services/api' import { useAppSelector } from '@renderer/store' @@ -19,7 +19,8 @@ interface Props { } const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic }) => { - const { assistant, removeTopic, updateTopic, updateTopics } = useAssistant(_assistant.id) + const { assistants } = useAssistants() + const { assistant, removeTopic, moveTopic, updateTopic, updateTopics } = useAssistant(_assistant.id) const { t } = useTranslation() const generating = useAppSelector((state) => state.runtime.generating) @@ -34,6 +35,15 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic [assistant.topics, removeTopic, setActiveTopic] ) + const onMoveTopic = useCallback( + (topic: Topic, toAssistant: Assistant) => { + const index = findIndex(assistant.topics, (t) => t.id === topic.id) + setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1]) + moveTopic(topic, toAssistant) + }, + [assistant.topics, moveTopic, setActiveTopic] + ) + const onSwitchTopic = useCallback( (topic: Topic) => { if (generating) { @@ -51,7 +61,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic { label: t('chat.topics.auto_rename'), key: 'auto-rename', - icon: , + icon: , async onClick() { const messages = await TopicManager.getTopicMessages(topic.id) if (messages.length >= 2) { @@ -79,6 +89,21 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic } ] + if (assistants.length > 1 && assistant.topics.length > 1) { + menus.push({ + label: t('chat.topics.move_to'), + key: 'move', + icon: , + children: assistants + .filter((a) => a.id !== assistant.id) + .map((a) => ({ + label: a.name, + key: a.id, + onClick: () => onMoveTopic(topic, a) + })) + }) + } + if (assistant.topics.length > 1) { menus.push({ type: 'divider' }) menus.push({ @@ -92,7 +117,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic return menus }, - [assistant, onDeleteTopic, t, updateTopic] + [assistant, assistants, onDeleteTopic, onMoveTopic, t, updateTopic] ) return (