import {errorText} from './text.ts'; import {useEffect, useState} from 'react'; import {getJSON} from './api.ts'; export type NoteScope = {segment_id: string} | {batch_id: string}; type Note = {id: string; created_at: string; scope: NoteScope; span_s: [number, number] | null; actor_ids: string[]; category: string; text: string; reviewer: string; provenance: {segment_id: string; artifact_sha256: string; generator_version: string}[]}; const CATEGORIES = {unnatural_motion: '运动不自然', unusable_view: '画面不可用', situation_missed: '情形没达成', insufficient_interaction: '交互不足', other: '其他'}; export function NotesPanel({scope, fingerprints, span, actors}: {scope: NoteScope; fingerprints: Record; span: [number, number] | null; actors: string[]}) { const [notes, setNotes] = useState([]), [text, setText] = useState(''), [reviewer, setReviewer] = useState(''), [category, setCategory] = useState('unnatural_motion'); const [error, setError] = useState(''), [saving, setSaving] = useState(false), [revision, setRevision] = useState(0), [open, setOpen] = useState(false); const key = 'segment_id' in scope ? 'segment_id' : 'batch_id', id = 'segment_id' in scope ? scope.segment_id : scope.batch_id; useEffect(() => { const controller = new AbortController(); getJSON<{notes: Note[]; errors: unknown[]}>('/api/v1/notes?' + new URLSearchParams({[key]: id}), controller.signal).then(data => {setNotes(data.notes); if (data.errors.length) setError('有保存记录不能读取,已保留原文件。');}).catch(e => {if (!controller.signal.aborted) setError(errorText(e));}); return () => controller.abort(); }, [key, id, revision]); async function save() { setSaving(true); setError(''); try { const response = await fetch('/api/v1/notes', {method: 'POST', credentials: 'same-origin', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({scope, span_s: span, actor_ids: actors, category, text, reviewer, expected_fingerprints: fingerprints})}); const value = await response.json(); if (!response.ok) throw Error(value.error?.message || String(response.status)); setText(''); setRevision(r => r + 1); setOpen(false); } catch (e) {setError(errorText(e));} finally {setSaving(false);} } return
审阅意见 · {notes.length}
{open &&

{span ? `${span[0].toFixed(2)}–${span[1].toFixed(2)} 秒` : '整批'} · {actors.join('、') || '未指定主体'}