Skip to content

Commit

Permalink
fix: prevent orphaned thread record when deleting active conversation (
Browse files Browse the repository at this point in the history
…#1883)

* fix: prevent orphaned thread record when deleting active conversation

* refactor: optimize thread deletion navigation logic
  • Loading branch information
hexart authored Feb 11, 2025
1 parent 9baa6e0 commit 0fb811b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions frontend/src/components/LeftSidebar/ThreadList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,23 @@ export function ThreadList({

const handleDeleteThread = () => {
if (!threadIdToDelete) return;
if (
threadIdToDelete === idToResume ||
threadIdToDelete === currentThreadId
) {
clear();
}

toast.promise(apiClient.deleteThread(threadIdToDelete), {
loading: (
<Translator path="threadHistory.thread.actions.delete.inProgress" />
),
success: () => {
if (
threadIdToDelete === idToResume ||
threadIdToDelete === currentThreadId
) {
clear();
}
if (threadIdToDelete === threadHistory.currentThreadId) {
navigate('/');
}
setThreadHistory((prev) => ({
...prev,
threads: prev?.threads?.filter((t) => t.id !== threadIdToDelete)
}));
navigate('/');
return (
<Translator path="threadHistory.thread.actions.delete.success" />
);
Expand Down

0 comments on commit 0fb811b

Please sign in to comment.