Wholesale JS -> TS migration of the frontend — stores, utils, actions,
and all Svelte component scripts adopt type annotations. Compile-time
surfaces (app.d.ts, lib/types/) added for shared DTO types.
Build plumbing:
- package.json: dev:frontend script that runs svelte-kit sync first
- tauri.conf.json: beforeDevCommand points at dev:frontend
- run.sh: dropped the sed-hack that temporarily blanked beforeDevCommand;
now relies on npm run dev:frontend to avoid double-Vite
- jsconfig.json: allowImportingTsExtensions
Preserves all Group 1 behaviour:
- page.svelte.ts keeps loadHistory / loadTasks Tauri-first, no
localStorage; saveTranscriptMeta + mapTranscriptRow + mapTaskRow
intact; update_task_cmd and update_transcript_meta_cmd invocations
carry the correct payload shape.
- Toasts, preferences stores typed without behaviour change.
- Viewer still routes segment edits through saveTranscriptMeta; the
Task 1.5 TODO markers are gone.
taskExtractor.ts is functionally improved during the migration:
- multi-task matches in the same sentence
- list-style shopping-verb expansion (get bread, milk, and cheese)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
/** Pad number to 2 digits */
|
|
export function pad(n: number): string {
|
|
return n.toString().padStart(2, "0");
|
|
}
|
|
|
|
/** Format seconds as M:SS (e.g. 1:05) */
|
|
export function formatTime(seconds: number): string {
|
|
if (!seconds || isNaN(seconds)) return "0:00";
|
|
const m = Math.floor(seconds / 60);
|
|
const s = Math.floor(seconds % 60).toString().padStart(2, "0");
|
|
return `${m}:${s}`;
|
|
}
|
|
|
|
/** Format seconds as human duration (e.g. 2m 30s) */
|
|
export function formatDuration(seconds: number): string {
|
|
if (!seconds) return "";
|
|
const m = Math.floor(seconds / 60);
|
|
const s = Math.round(seconds % 60);
|
|
return m > 0 ? `${m}m ${s}s` : `${s}s`;
|
|
}
|
|
|
|
/** Format ISO timestamp as D Mon HH:MM (e.g. 15 Mar 18:11) */
|
|
export function formatTimestamp(iso: string | null | undefined): string {
|
|
if (!iso) return "";
|
|
const d = new Date(iso);
|
|
return d.toLocaleDateString("en-GB", { day: "numeric", month: "short" }) +
|
|
" " + d.toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit" });
|
|
}
|
|
|
|
/** Format seconds as SRT timestamp (HH:MM:SS,mmm) */
|
|
export function formatTimeSRT(seconds: number): string {
|
|
const h = Math.floor(seconds / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const s = Math.floor(seconds % 60);
|
|
const ms = Math.floor((seconds % 1) * 1000);
|
|
return `${pad(h)}:${pad(m)}:${pad(s)},${ms.toString().padStart(3, "0")}`;
|
|
}
|
|
|
|
/** Format seconds as VTT timestamp (HH:MM:SS.mmm) */
|
|
export function formatTimeVTT(seconds: number): string {
|
|
const h = Math.floor(seconds / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const s = Math.floor(seconds % 60);
|
|
const ms = Math.floor((seconds % 1) * 1000);
|
|
return `${pad(h)}:${pad(m)}:${pad(s)}.${ms.toString().padStart(3, "0")}`;
|
|
}
|