feat: Enhance topic message clearing functionality
关于“清空话题”的Bug反馈 #2107 close #2107
This commit is contained in:
parent
83c8f06b81
commit
d5b9c35f0a
@ -162,10 +162,19 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
|
|||||||
setTimeout(() => EventEmitter.emit(EVENT_NAMES.AI_AUTO_RENAME), 100)
|
setTimeout(() => EventEmitter.emit(EVENT_NAMES.AI_AUTO_RENAME), 100)
|
||||||
}),
|
}),
|
||||||
EventEmitter.on(EVENT_NAMES.AI_AUTO_RENAME, autoRenameTopic),
|
EventEmitter.on(EVENT_NAMES.AI_AUTO_RENAME, autoRenameTopic),
|
||||||
EventEmitter.on(EVENT_NAMES.CLEAR_MESSAGES, () => {
|
EventEmitter.on(EVENT_NAMES.CLEAR_MESSAGES, (data: Topic) => {
|
||||||
|
const defaultTopic = getDefaultTopic(assistant.id)
|
||||||
|
|
||||||
|
// Clear messages of other topics
|
||||||
|
if (data && data.id !== topic.id) {
|
||||||
|
TopicManager.clearTopicMessages(data.id)
|
||||||
|
updateTopic({ ...data, name: defaultTopic.name, messages: [] })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear messages of current topic
|
||||||
setMessages([])
|
setMessages([])
|
||||||
setDisplayMessages([])
|
setDisplayMessages([])
|
||||||
const defaultTopic = getDefaultTopic(assistant.id)
|
|
||||||
const _topic = getTopic(assistant, topic.id)
|
const _topic = getTopic(assistant, topic.id)
|
||||||
_topic && updateTopic({ ..._topic, name: defaultTopic.name, messages: [] })
|
_topic && updateTopic({ ..._topic, name: defaultTopic.name, messages: [] })
|
||||||
TopicManager.clearTopicMessages(topic.id)
|
TopicManager.clearTopicMessages(topic.id)
|
||||||
|
|||||||
@ -60,17 +60,17 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
|||||||
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
|
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onClearMessages = useCallback(() => {
|
const onClearMessages = useCallback((topic: Topic) => {
|
||||||
window.keyv.set(EVENT_NAMES.CHAT_COMPLETION_PAUSED, true)
|
window.keyv.set(EVENT_NAMES.CHAT_COMPLETION_PAUSED, true)
|
||||||
store.dispatch(setGenerating(false))
|
store.dispatch(setGenerating(false))
|
||||||
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES)
|
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES, topic)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleConfirmDelete = useCallback(
|
const handleConfirmDelete = useCallback(
|
||||||
async (topic: Topic, e: React.MouseEvent) => {
|
async (topic: Topic, e: React.MouseEvent) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (assistant.topics.length === 1) {
|
if (assistant.topics.length === 1) {
|
||||||
return onClearMessages()
|
return onClearMessages(topic)
|
||||||
}
|
}
|
||||||
await modelGenerating()
|
await modelGenerating()
|
||||||
const index = findIndex(assistant.topics, (t) => t.id === topic.id)
|
const index = findIndex(assistant.topics, (t) => t.id === topic.id)
|
||||||
@ -187,7 +187,7 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
|||||||
window.modal.confirm({
|
window.modal.confirm({
|
||||||
title: t('chat.input.clear.content'),
|
title: t('chat.input.clear.content'),
|
||||||
centered: true,
|
centered: true,
|
||||||
onOk: onClearMessages
|
onOk: () => onClearMessages(topic)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user