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:
parent
866ce86cc0
commit
fdb856199a
@ -98,11 +98,13 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
|
||||
const onDeleteTopic = useCallback(
|
||||
async (topic: Topic) => {
|
||||
await modelGenerating()
|
||||
const index = findIndex(assistant.topics, (t) => t.id === topic.id)
|
||||
setActiveTopic(assistant.topics[index + 1 === assistant.topics.length ? index - 1 : index + 1])
|
||||
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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user