26 lines
988 B
TypeScript
26 lines
988 B
TypeScript
"use client";
|
|
// PEP-225: the story's status badge, updated in place from the live channel (`task:<id>` rows) —
|
|
// the rest of the page follows with the next server re-render.
|
|
import { useState, useEffect } from "react";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { useT } from "@/components/I18n";
|
|
import { useLiveIsland } from "@/lib/live";
|
|
import { TASK_STATUS } from "@/lib/status";
|
|
|
|
export function LiveTaskStatus({ taskId, status: initial }: { taskId: number; status: string }) {
|
|
const t = useT();
|
|
const [status, setStatus] = useState(initial);
|
|
useEffect(() => setStatus(initial), [initial]);
|
|
useLiveIsland((e) => {
|
|
const row = e.tasks?.find((r) => r.id === taskId);
|
|
if (row) setStatus(row.status);
|
|
return []; // the page around depends on the status too
|
|
});
|
|
const s = TASK_STATUS[status] ?? { label: status, tone: "muted" as const };
|
|
return (
|
|
<Badge variant={s.tone} data-live-status={status}>
|
|
{t.text(s.label)}
|
|
</Badge>
|
|
);
|
|
}
|