mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 22:39:36 +08:00
fix: move handling to clearTopic
This commit is contained in:
parent
59a50c346b
commit
499ad5fabf
@ -61,7 +61,7 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
|
|||||||
const [isLoadingMore, setIsLoadingMore] = useState(false)
|
const [isLoadingMore, setIsLoadingMore] = useState(false)
|
||||||
const [isProcessingContext, setIsProcessingContext] = useState(false)
|
const [isProcessingContext, setIsProcessingContext] = useState(false)
|
||||||
|
|
||||||
const { addTopic } = useAssistant(assistant.id)
|
const { addTopic, updateTopic, assistant: currentAssistant } = useAssistant(assistant.id)
|
||||||
const { showPrompt, messageNavigation } = useSettings()
|
const { showPrompt, messageNavigation } = useSettings()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@ -105,15 +105,28 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
|
|||||||
|
|
||||||
const clearTopic = useCallback(
|
const clearTopic = useCallback(
|
||||||
async (data: Topic) => {
|
async (data: Topic) => {
|
||||||
if (data && data.id !== topic.id) {
|
const targetTopic = data && data.id !== topic.id ? data : topic
|
||||||
await clearTopicMessages(data.id)
|
const isCurrentTopic = targetTopic.id === topic.id
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await clearTopicMessages()
|
if (!isCurrentTopic) {
|
||||||
setDisplayMessages([])
|
await clearTopicMessages(data.id)
|
||||||
|
} else {
|
||||||
|
await clearTopicMessages()
|
||||||
|
setDisplayMessages([])
|
||||||
|
}
|
||||||
|
if (currentAssistant?.topics.length === 1) {
|
||||||
|
const updatedTopic = {
|
||||||
|
...targetTopic,
|
||||||
|
name: t('chat.default.topic.name'),
|
||||||
|
isNameManuallyEdited: false
|
||||||
|
}
|
||||||
|
updateTopic(updatedTopic)
|
||||||
|
if (isCurrentTopic) {
|
||||||
|
setActiveTopic(updatedTopic)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[clearTopicMessages, topic.id]
|
[clearTopicMessages, topic, currentAssistant?.topics.length, updateTopic, setActiveTopic, t]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -127,26 +127,11 @@ export const Topics: React.FC<Props> = ({ assistant: _assistant, activeTopic, se
|
|||||||
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
|
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onClearMessages = useCallback(
|
const onClearMessages = useCallback((topic: Topic) => {
|
||||||
(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, topic)
|
||||||
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES, topic)
|
}, [])
|
||||||
|
|
||||||
if (assistant.topics.length === 1) {
|
|
||||||
const updatedTopic = {
|
|
||||||
...topic,
|
|
||||||
name: t('chat.default.topic.name'),
|
|
||||||
isNameManuallyEdited: false
|
|
||||||
}
|
|
||||||
updateTopic(updatedTopic)
|
|
||||||
if (topic.id === activeTopic.id) {
|
|
||||||
setActiveTopic(updatedTopic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[assistant.topics.length, t, updateTopic, activeTopic.id, setActiveTopic]
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleConfirmDelete = useCallback(
|
const handleConfirmDelete = useCallback(
|
||||||
async (topic: Topic, e: React.MouseEvent) => {
|
async (topic: Topic, e: React.MouseEvent) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user