fix: resolve the key before deleting a draft from the drafts page

The page lists a live editor's draft under its chosen name, so the name has
to be resolved to a storage key now that the adapter takes one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guilhem Lemouel
2026-09-24 08:43:25 +02:00
co-authored by Claude Opus 5
parent c71733681f
commit dc1f485a86
@@ -3,7 +3,8 @@
import {
clearGlobalDrafts,
deleteGlobalDraft,
listGlobalDrafts
listGlobalDrafts,
resolveDraftTarget
} from '$lib/components/copilot/chat/global/userDraftAdapter'
import type { WorkspaceItem } from '$lib/components/copilot/chat/global/workspaceItems'
import { goto } from '$lib/navigation'
@@ -49,9 +50,19 @@
return `${item.type}:${item.triggerKind ?? '-'}:${item.path}`
}
// A live editor's draft is listed under its chosen name, so the key to delete has to be
// resolved from it; a persisted row is already listed under its storage key.
function draftTargetOf(item: WorkspaceItem) {
return resolveDraftTarget($workspaceStore!, {
type: item.type,
path: item.path,
triggerKind: item.triggerKind
})
}
async function deleteDraft(item: WorkspaceItem) {
if (!$workspaceStore) return
await deleteGlobalDraft($workspaceStore, item.type, item.path, item.triggerKind)
await deleteGlobalDraft($workspaceStore, item.type, await draftTargetOf(item), item.triggerKind)
refreshDrafts()
}
@@ -62,7 +73,12 @@
// Continue past a per-row failure so one bad delete doesn't strand the rest.
for (const item of [...drafts]) {
try {
await deleteGlobalDraft($workspaceStore, item.type, item.path, item.triggerKind)
await deleteGlobalDraft(
$workspaceStore,
item.type,
await draftTargetOf(item),
item.triggerKind
)
} catch (e) {
console.error('Failed to clear draft', item.path, e)
}