refactor(viewer): drop kon_history localStorage; route edits through update_transcript

This commit is contained in:
2026-04-19 16:06:19 +01:00
parent 5e3bc369de
commit 6113e6d784
2 changed files with 29 additions and 15 deletions

View File

@@ -83,9 +83,9 @@ export function saveProfiles() {
// array is seeded empty on module init and hydrated from SQLite on boot
// in the desktop runtime. Browser preview (no Tauri) shows an empty list.
//
// The previous `kon_history` localStorage read-cache was removed to kill
// the cold-start flicker where the UI painted stale localStorage data and
// then overwrote it from SQLite a tick later.
// The previous localStorage history read-cache was removed to kill the
// cold-start flicker where the UI painted stale cached data and then
// overwrote it from SQLite a tick later.
import { invoke } from "@tauri-apps/api/core";
import { hasTauriRuntime } from "$lib/utils/runtime.js";

View File

@@ -200,8 +200,11 @@
function toggleStar(idx) {
if (item?.segments) {
// TODO: Phase 2 remaining Task 1.5 — starred is not a SQLite column
// on the transcripts table yet, so this mutation is in-memory only
// and will not survive a reload. Task 1.5 will extend update_transcript
// (and the transcripts schema) to carry starred segment state.
item.segments[idx].starred = !item.segments[idx].starred;
saveItemToHistory();
}
}
@@ -214,21 +217,32 @@
}
}
// Persist edits back to SQLite via update_transcript (the canonical store).
// Only `text` and `title` are accepted by update_transcript today. Segment
// structure, segment-level starred flags, and manualTags are not SQLite
// columns yet — Phase 2 remaining Task 1.5 will extend the command and the
// transcripts schema to cover those. Until then, segment-level edits that
// change `item.text` (the joined full transcript) survive reload; the
// segment array itself does not.
//
// The cross-window `kon_viewer_item` localStorage payload stays in sync so
// a second viewer window hydrating from it reflects the latest edit.
function saveItemToHistory() {
// Persist edits back to localStorage history
if (!item) return;
// Update the cross-window payload only. The old localStorage history
// cache was removed as part of the SQLite-canonical refactor.
try {
const raw = localStorage.getItem("kon_history");
if (raw) {
const hist = JSON.parse(raw);
const idx = hist.findIndex((h) => h.id === item.id);
if (idx >= 0) {
hist[idx] = { ...hist[idx], segments: item.segments, text: item.text };
localStorage.setItem("kon_history", JSON.stringify(hist));
}
}
// Also update the viewer item cache
localStorage.setItem("kon_viewer_item", JSON.stringify(item));
} catch {}
// Best-effort SQLite persistence. Silently ignored in browser preview
// (no Tauri runtime) — matches the main-window store's behaviour.
invoke("update_transcript", {
id: String(item.id),
text: item.text ?? null,
title: item.title ?? null,
}).catch((err) => {
console.warn("viewer saveItemToHistory: update_transcript failed", err);
});
}
function scheduleTextSave() {