Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(web-app): tell the user when a conversation could not be deleted

thinhlpgef7ebc080bb2
diff --git a/web-app/src/hooks/__tests__/useThreads.coverage.test.ts b/web-app/src/hooks/__tests__/useThreads.coverage.test.ts
index f8ffbff5e..288955d7c 100644
--- a/web-app/src/hooks/__tests__/useThreads.coverage.test.ts
+++ b/web-app/src/hooks/__tests__/useThreads.coverage.test.ts
@@ -24,7 +24,7 @@ vi.mock('fzf', () => ({
}))
const mockCreateThread = vi.fn()
-const mockDeleteThread = vi.fn()
+const mockDeleteThread = vi.fn().mockResolvedValue(undefined)
const mockUpdateThread = vi.fn()
vi.mock('@/hooks/useServiceHub', () => ({
diff --git a/web-app/src/hooks/useThreads.ts b/web-app/src/hooks/useThreads.ts
index 1eff67ea9..7a47850c2 100644
--- a/web-app/src/hooks/useThreads.ts
+++ b/web-app/src/hooks/useThreads.ts
@@ -1,4 +1,6 @@
import { create } from 'zustand'
+import { toast } from 'sonner'
+import { i18n } from '@/i18n/react-i18next-compat'
import { ulid } from 'ulidx'
import { getServiceHub } from '@/hooks/useServiceHub'
import { Fzf } from 'fzf'
@@ -131,7 +133,17 @@ const deleteThreadEverywhere = (threadId: string, thread: Thread | undefined) =>
return
}
cleanupThreadArtifacts(threadId)
- getServiceHub().threads().deleteThread(threadId)
+ // The row is already gone from the list; when the files stay behind the
+ // conversation comes back on restart, so the user is told now.
+ void getServiceHub()
+ .threads()
+ .deleteThread(threadId)
+ .catch((error) => {
+ console.error(`Could not delete thread ${threadId}:`, error)
+ toast.error(i18n.t('common:deleteThreadFailed'), {
+ description: String(error),
+ })
+ })
}
export const useThreads = create<ThreadState>()((set, get) => ({
diff --git a/web-app/src/locales/en/common.json b/web-app/src/locales/en/common.json
index 7a0be936a..43f21d5b9 100644
--- a/web-app/src/locales/en/common.json
+++ b/web-app/src/locales/en/common.json
@@ -939,5 +939,6 @@
"body_other": "{{count}} items from this task's old folder (links, or files Jan was not allowed to read) were not copied. The original folder is kept as it was.",
"show": "Show original folder"
}
- }
+ },
+ "deleteThreadFailed": "Could not delete the conversation. It may come back after a restart."
}