diff --git a/src/lib/pages/HistoryPage.svelte b/src/lib/pages/HistoryPage.svelte index da790f8..c0c2199 100644 --- a/src/lib/pages/HistoryPage.svelte +++ b/src/lib/pages/HistoryPage.svelte @@ -4,9 +4,9 @@ import { invoke } from "@tauri-apps/api/core"; import { history, - saveHistory, saveTranscriptMeta, deleteFromHistory, + deleteFromHistoryById, renameHistoryEntry, } from "$lib/stores/page.svelte.js"; import { toasts } from "$lib/stores/toasts.svelte.js"; @@ -228,12 +228,27 @@ return items; }); - function clearAll() { + async function clearAll() { if (!confirm("Delete all history? This can't be undone.")) return; + const ids = history.map((entry) => entry.id); history.splice(0); - saveHistory(); expandedId = null; stopPlayback(); + let failed = 0; + for (const id of ids) { + try { + await invoke("delete_transcript", { id: String(id) }); + } catch (err) { + failed++; + console.warn("clearAll: SQLite delete failed", id, err); + } + } + if (failed > 0) { + toasts.error( + "Some history entries could not be deleted", + `${failed} of ${ids.length} failed to delete from disk and may reappear after restart.`, + ); + } } function toggleExpand(id) { @@ -453,7 +468,7 @@ `Delete ${selected.size} transcript${selected.size === 1 ? "" : "s"}?`, ); if (!yes) return; - for (const id of selected) deleteFromHistory(id); + for (const id of selected) deleteFromHistoryById(id); clearSelection(); } diff --git a/src/lib/stores/page.svelte.ts b/src/lib/stores/page.svelte.ts index 08bb3d0..80845f2 100644 --- a/src/lib/stores/page.svelte.ts +++ b/src/lib/stores/page.svelte.ts @@ -223,8 +223,6 @@ if (typeof window !== "undefined" && hasTauriRuntime()) { loadHistory().catch(() => {}); } -export function saveHistory() {} - export async function addToHistory(entry: TranscriptWriteEntry) { const normalised = normaliseTranscriptEntry(entry); history.unshift(normalised); @@ -323,6 +321,12 @@ export function deleteFromHistory(index: number) { .catch((err) => console.warn("deleteFromHistory: SQLite delete failed", err)); } +export function deleteFromHistoryById(id: string) { + const idx = history.findIndex((entry) => String(entry.id) === String(id)); + if (idx === -1) return; + deleteFromHistory(idx); +} + export const tasks = $state([]); function mapTaskRow(row: TaskDto): TaskEntry {