'use client'; import { useState } from 'react'; import { adminFetch } from '@/lib/admin-fetch'; import { Time } from '@/lib/time'; import type { AdminAnnotation } from '@/lib/types'; import { AdminPage, ErrorNote, Field, Panel, Toast, btnPrimary, inputCls, useAdmin } from './shared'; export function Annotations() { const { data, err, reload } = useAdmin<{ annotations: AdminAnnotation[] }>('/annotations'); const [form, setForm] = useState(() => ({ ts: new Date().toISOString().slice(0, 19) + 'Z', scope_type: 'global', scope_id: '', text: '' })); const [msg, setMsg] = useState(null); const [actErr, setActErr] = useState(null); return (
{ e.preventDefault(); setActErr(null); adminFetch('/annotations', { method: 'POST', body: { ...form, scope_id: form.scope_id || null } }) .then(() => { setMsg('Annotation saved'); setForm({ ...form, text: '' }); reload(); }) .catch((er: unknown) => setActErr(String(er))) .finally(() => setTimeout(() => setMsg(null), 3000)); }} > setForm({ ...form, ts: e.target.value })} className={`${inputCls} num w-full`} required /> setForm({ ...form, scope_id: e.target.value })} className={`${inputCls} num w-full`} /> setForm({ ...form, text: e.target.value })} className={`${inputCls} w-full`} required />
    {(data?.annotations ?? []).map((a, i) => (
  • {a.text}

  • ))}
); }