From 3f3b9308190b3e5cae860959ef637561fe613d20 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 22 Jul 2024 10:22:47 +0800 Subject: [PATCH] fix: disabled switch topic while generating message --- src/renderer/src/i18n/index.ts | 6 ++++-- src/renderer/src/pages/home/components/Topics.tsx | 12 +++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/i18n/index.ts b/src/renderer/src/i18n/index.ts index acf89b1e..30941599 100644 --- a/src/renderer/src/i18n/index.ts +++ b/src/renderer/src/i18n/index.ts @@ -41,7 +41,8 @@ const resources = { 'error.enter.model': 'Please select a model first', 'api.connection.failed': 'Connection failed', 'api.connection.success': 'Connection successful', - 'chat.completion.paused': 'Chat completion paused' + 'chat.completion.paused': 'Chat completion paused', + 'topics.switch.disabled': 'Switching topics is disabled while the assistant is generating' }, assistant: { 'default.name': '😀 Default Assistant', @@ -174,7 +175,8 @@ const resources = { 'error.enter.model': '请选择一个模型', 'api.connection.failed': '连接失败', 'api.connection.success': '连接成功', - 'chat.completion.paused': '会话已停止' + 'chat.completion.paused': '会话已停止', + 'topics.switch.disabled': '模型回复完成后才能切换话题' }, assistant: { 'default.name': '😃 默认助手 - Assistant', diff --git a/src/renderer/src/pages/home/components/Topics.tsx b/src/renderer/src/pages/home/components/Topics.tsx index 4eb07aac..61afcc80 100644 --- a/src/renderer/src/pages/home/components/Topics.tsx +++ b/src/renderer/src/pages/home/components/Topics.tsx @@ -11,6 +11,7 @@ import LocalStorage from '@renderer/services/storage' import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea/dnd' import { droppableReorder } from '@renderer/utils' import { useTranslation } from 'react-i18next' +import { useAppSelector } from '@renderer/store' interface Props { assistant: Assistant @@ -22,6 +23,7 @@ const Topics: FC = ({ assistant, activeTopic, setActiveTopic }) => { const { showRightSidebar } = useShowRightSidebar() const { removeTopic, updateTopic, removeAllTopics, updateTopics } = useAssistant(assistant.id) const { t } = useTranslation() + const generating = useAppSelector((state) => state.runtime.generating) const getTopicMenuItems = (topic: Topic) => { const menus: MenuProps['items'] = [ @@ -82,6 +84,14 @@ const Topics: FC = ({ assistant, activeTopic, setActiveTopic }) => { } } + const onSwitchTopic = (topic: Topic) => { + if (generating) { + window.message.info({ content: t('message.topics.switch.disabled'), key: 'switch-topic' }) + return + } + setActiveTopic(topic) + } + return ( @@ -111,7 +121,7 @@ const Topics: FC = ({ assistant, activeTopic, setActiveTopic }) => { setActiveTopic(topic)}> + onClick={() => onSwitchTopic(topic)}> {topic.name}