fix(TopicsTab): Ensure active topic is updated correctly on deletion

- Added a check to update the active topic only if the deleted topic is currently active, preventing potential errors in topic navigation.
This commit is contained in:
ousugo 2025-03-13 15:00:34 +08:00 committed by 亢奋猫
parent 866ce86cc0
commit fdb856199a

View File

@ -98,11 +98,13 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
const onDeleteTopic = useCallback(
async (topic: Topic) => {
await modelGenerating()
if (topic.id === activeTopic?.id) {
const index = findIndex(assistant.topics, (t) => t.id === topic.id)
setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? index - 1 : index + 1])
}
removeTopic(topic)
},
[assistant.topics, removeTopic, setActiveTopic]
[assistant.topics, removeTopic, setActiveTopic, activeTopic]
)
const onMoveTopic = useCallback(