diff --git a/src/renderer/src/pages/home/Messages/Messages.tsx b/src/renderer/src/pages/home/Messages/Messages.tsx index 7e0e03a77..1b0dec81b 100644 --- a/src/renderer/src/pages/home/Messages/Messages.tsx +++ b/src/renderer/src/pages/home/Messages/Messages.tsx @@ -62,7 +62,7 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic, o const [isLoadingMore, setIsLoadingMore] = 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 { t } = useTranslation() const dispatch = useAppDispatch() @@ -106,15 +106,28 @@ const Messages: React.FC = ({ assistant, topic, setActiveTopic, o const clearTopic = useCallback( async (data: Topic) => { - if (data && data.id !== topic.id) { - await clearTopicMessages(data.id) - return - } + const targetTopic = data && data.id !== topic.id ? data : topic + const isCurrentTopic = targetTopic.id === topic.id - await clearTopicMessages() - setDisplayMessages([]) + if (!isCurrentTopic) { + 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(() => {