refactor(viewer): drop kon_history localStorage; route edits through update_transcript
This commit is contained in:
@@ -83,9 +83,9 @@ export function saveProfiles() {
|
|||||||
// array is seeded empty on module init and hydrated from SQLite on boot
|
// 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.
|
// in the desktop runtime. Browser preview (no Tauri) shows an empty list.
|
||||||
//
|
//
|
||||||
// The previous `kon_history` localStorage read-cache was removed to kill
|
// The previous localStorage history read-cache was removed to kill the
|
||||||
// the cold-start flicker where the UI painted stale localStorage data and
|
// cold-start flicker where the UI painted stale cached data and then
|
||||||
// then overwrote it from SQLite a tick later.
|
// overwrote it from SQLite a tick later.
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { hasTauriRuntime } from "$lib/utils/runtime.js";
|
import { hasTauriRuntime } from "$lib/utils/runtime.js";
|
||||||
|
|||||||
@@ -200,8 +200,11 @@
|
|||||||
|
|
||||||
function toggleStar(idx) {
|
function toggleStar(idx) {
|
||||||
if (item?.segments) {
|
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;
|
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() {
|
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 {
|
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));
|
localStorage.setItem("kon_viewer_item", JSON.stringify(item));
|
||||||
} catch {}
|
} 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() {
|
function scheduleTextSave() {
|
||||||
|
|||||||
Reference in New Issue
Block a user