fix: Disable topic switching and movement during rendering.

- Added functionality to disable topic switching and movement when rendering is in progress.
This commit is contained in:
kangfenmao 2024-09-19 23:01:21 +08:00
parent 353e497642
commit 60e87e8a22

View File

@ -26,28 +26,36 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
const onDeleteTopic = useCallback( const onDeleteTopic = useCallback(
(topic: Topic) => { (topic: Topic) => {
if (generating) {
window.message.warning({ content: t('message.switch.disabled'), key: 'generating' })
return
}
if (assistant.topics.length > 1) { if (assistant.topics.length > 1) {
const index = findIndex(assistant.topics, (t) => t.id === topic.id) const index = findIndex(assistant.topics, (t) => t.id === topic.id)
setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1]) setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1])
removeTopic(topic) removeTopic(topic)
} }
}, },
[assistant.topics, removeTopic, setActiveTopic] [assistant.topics, generating, removeTopic, setActiveTopic, t]
) )
const onMoveTopic = useCallback( const onMoveTopic = useCallback(
(topic: Topic, toAssistant: Assistant) => { (topic: Topic, toAssistant: Assistant) => {
if (generating) {
window.message.warning({ content: t('message.switch.disabled'), key: 'generating' })
return
}
const index = findIndex(assistant.topics, (t) => t.id === topic.id) const index = findIndex(assistant.topics, (t) => t.id === topic.id)
setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1]) setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? 0 : index + 1])
moveTopic(topic, toAssistant) moveTopic(topic, toAssistant)
}, },
[assistant.topics, moveTopic, setActiveTopic] [assistant.topics, generating, moveTopic, setActiveTopic, t]
) )
const onSwitchTopic = useCallback( const onSwitchTopic = useCallback(
(topic: Topic) => { (topic: Topic) => {
if (generating) { if (generating) {
window.message.warning({ content: t('message.switch.disabled'), key: 'switch-assistant' }) window.message.warning({ content: t('message.switch.disabled'), key: 'generating' })
return return
} }
setActiveTopic(topic) setActiveTopic(topic)