peppa/apps/web/components/LiveTaskStatus.tsx

27 lines
1.1 KiB
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, rollout = false }: { taskId: number; status: string; /** PEP-278: done, the version with the changes is not running yet. */ rollout?: boolean }) {
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 shown = status === "done" && rollout ? "rollout" : status;
const s = TASK_STATUS[shown] ?? { label: shown, tone: "muted" as const };
return (
<Badge variant={s.tone} data-live-status={shown}>
{t.text(s.label)}
</Badge>
);
}