🐛fix: delete all should not include fav thread (#5864)

This commit is contained in:
Faisal Amir 2025-07-22 19:51:59 +07:00 committed by GitHub
parent 1dd5b810c2
commit 7b3b6cc8be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,12 +109,32 @@ export const useThreads = create<ThreadState>()((set, get) => ({
deleteAllThreads: () => {
set((state) => {
const allThreadIds = Object.keys(state.threads)
allThreadIds.forEach((threadId) => {
const favoriteThreadIds = allThreadIds.filter(
(threadId) => state.threads[threadId].isFavorite
)
const nonFavoriteThreadIds = allThreadIds.filter(
(threadId) => !state.threads[threadId].isFavorite
)
// Only delete non-favorite threads
nonFavoriteThreadIds.forEach((threadId) => {
deleteThread(threadId)
})
// Keep only favorite threads
const remainingThreads = favoriteThreadIds.reduce(
(acc, threadId) => {
acc[threadId] = state.threads[threadId]
return acc
},
{} as Record<string, Thread>
)
return {
threads: {},
searchIndex: null, // Or new Fzf([], {selector...})
threads: remainingThreads,
searchIndex: new Fzf<Thread[]>(Object.values(remainingThreads), {
selector: (item: Thread) => item.title,
}),
}
})
},