Files
call-recorder/ui/src/routes/Prompt.svelte
T
2026-11-05 15:48:55 +01:00

104 lines
2.4 KiB
Svelte

<script lang="ts">
import { onMount } from 'svelte'
import {
discardCall,
errorText,
getPendingPrompt,
onCallEnded,
transcribeCall,
type CallId,
type PendingPrompt,
} from '../lib/api'
import { formatMinutes, formatTimeRange } from '../lib/format'
let brief = $state<PendingPrompt | null>(null)
let busy = $state(false)
let error = $state('')
function show(next: PendingPrompt | null) {
if (next?.id !== brief?.id) error = ''
brief = next
}
// The backend queues ended calls; this window always shows the oldest.
// It stays loaded while hidden and may have missed an event, so it also
// asks whenever it is shown again.
const refresh = () =>
getPendingPrompt()
.then(show)
.catch((err) => (error = errorText(err)))
onMount(() => {
const unlisten = onCallEnded(refresh)
refresh()
window.addEventListener('focus', refresh)
return () => {
window.removeEventListener('focus', refresh)
unlisten.then((off) => off())
}
})
async function run(action: (id: CallId) => Promise<void>) {
if (!brief) return
busy = true
error = ''
try {
await action(brief.id)
// Decided: show the next queued call (the backend hides the window
// once none is left).
await refresh()
} catch (err) {
error = errorText(err)
} finally {
busy = false
}
}
</script>
<main class="prompt">
{#if brief}
<div class="title">{brief.app} · {formatMinutes(brief.duration_secs)}</div>
<div class="muted">{formatTimeRange(brief.started_at, brief.ended_at)}</div>
{#if brief.more_waiting > 0}
<div class="muted">Weitere Gespräche warten: {brief.more_waiting}</div>
{/if}
<div class="actions">
<button class="btn primary" disabled={busy} onclick={() => run(transcribeCall)}>
Transkribieren
</button>
<button class="btn danger" disabled={busy} onclick={() => run(discardCall)}>Verwerfen</button>
</div>
{:else}
<p class="muted">Kein Gespräch wartet auf eine Entscheidung.</p>
{/if}
{#if error}
<div class="error">{error}</div>
{/if}
</main>
<style>
:global(body:has(.prompt)) {
overflow: hidden;
}
.prompt {
min-height: 100vh;
background: var(--surface);
padding: 14px;
}
.title {
font-weight: 600;
}
.actions {
display: flex;
gap: 8px;
margin-top: 14px;
}
.error {
margin-top: 8px;
}
</style>