fix: disable switch while assistant generating message

This commit is contained in:
kangfenmao 2024-07-22 11:28:26 +08:00
parent e9a7735fce
commit ac3cfe2878
3 changed files with 14 additions and 4 deletions

View File

@ -42,7 +42,7 @@ const resources = {
'api.connection.failed': 'Connection failed', 'api.connection.failed': 'Connection failed',
'api.connection.success': 'Connection successful', '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' 'switch.disabled': 'Switching is disabled while the assistant is generating'
}, },
assistant: { assistant: {
'default.name': '😀 Default Assistant', 'default.name': '😀 Default Assistant',
@ -176,7 +176,7 @@ const resources = {
'api.connection.failed': '连接失败', 'api.connection.failed': '连接失败',
'api.connection.success': '连接成功', 'api.connection.success': '连接成功',
'chat.completion.paused': '会话已停止', 'chat.completion.paused': '会话已停止',
'topics.switch.disabled': '模型回复完成后才能切换话题' 'switch.disabled': '模型回复完成后才能切换'
}, },
assistant: { assistant: {
'default.name': '😃 默认助手 - Assistant', 'default.name': '😃 默认助手 - Assistant',

View File

@ -3,6 +3,7 @@ import { DragDropContext, Draggable, Droppable, DropResult } from '@hello-pangea
import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup' import AssistantSettingPopup from '@renderer/components/Popups/AssistantSettingPopup'
import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant' import { useAssistant, useAssistants } from '@renderer/hooks/useAssistant'
import { getDefaultTopic } from '@renderer/services/assistant' import { getDefaultTopic } from '@renderer/services/assistant'
import { useAppSelector } from '@renderer/store'
import { Assistant } from '@renderer/types' import { Assistant } from '@renderer/types'
import { droppableReorder, uuid } from '@renderer/utils' import { droppableReorder, uuid } from '@renderer/utils'
import { Dropdown } from 'antd' import { Dropdown } from 'antd'
@ -21,6 +22,7 @@ interface Props {
const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAssistant }) => { const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAssistant }) => {
const { assistants, removeAssistant, addAssistant, updateAssistants } = useAssistants() const { assistants, removeAssistant, addAssistant, updateAssistants } = useAssistants()
const { updateAssistant } = useAssistant(activeAssistant.id) const { updateAssistant } = useAssistant(activeAssistant.id)
const generating = useAppSelector((state) => state.runtime.generating)
const { t } = useTranslation() const { t } = useTranslation()
@ -70,6 +72,14 @@ const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAs
} }
} }
const onSwitchAssistant = (assistant: Assistant) => {
if (generating) {
window.message.warning({ content: t('message.switch.disabled'), key: 'switch-assistant' })
return
}
setActiveAssistant(assistant)
}
return ( return (
<Container> <Container>
<DragDropContext onDragEnd={onDragEnd}> <DragDropContext onDragEnd={onDragEnd}>
@ -82,7 +92,7 @@ const Assistants: FC<Props> = ({ activeAssistant, setActiveAssistant, onCreateAs
<div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}> <div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
<Dropdown key={assistant.id} menu={{ items: getMenuItems(assistant) }} trigger={['contextMenu']}> <Dropdown key={assistant.id} menu={{ items: getMenuItems(assistant) }} trigger={['contextMenu']}>
<AssistantItem <AssistantItem
onClick={() => setActiveAssistant(assistant)} onClick={() => onSwitchAssistant(assistant)}
className={assistant.id === activeAssistant?.id ? 'active' : ''}> className={assistant.id === activeAssistant?.id ? 'active' : ''}>
<AssistantName>{assistant.name}</AssistantName> <AssistantName>{assistant.name}</AssistantName>
</AssistantItem> </AssistantItem>

View File

@ -86,7 +86,7 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
const onSwitchTopic = (topic: Topic) => { const onSwitchTopic = (topic: Topic) => {
if (generating) { if (generating) {
window.message.info({ content: t('message.topics.switch.disabled'), key: 'switch-topic' }) window.message.warning({ content: t('message.switch.disabled'), key: 'switch-assistant' })
return return
} }
setActiveTopic(topic) setActiveTopic(topic)