douyinWEB/frontend/src/components/UploadTimeline.tsx
2026-08-15 04:59:15 -05:00

93 lines
2.8 KiB
TypeScript

"use client";
import { fmtTs } from "@/lib/api";
export type TimelineJob = {
id: string;
upload_at?: number;
status?: string;
anchor_name?: string;
channel_name?: string;
clip_ready?: boolean;
can_upload_now?: boolean;
};
export type TimelineHour = {
hour: number;
label: string;
count: number;
is_past?: boolean;
is_current?: boolean;
jobs: TimelineJob[];
};
export function UploadTimeline({
hours,
nowHour,
onUploadNow,
}: {
hours?: TimelineHour[];
nowHour?: number;
onUploadNow?: (job: TimelineJob) => void;
}) {
const rows = hours || [];
if (!rows.length) {
return <p className="text-xs text-slate-500">暂无排程时间轴</p>;
}
const max = Math.max(1, ...rows.map((h) => h.count || 0));
return (
<div className="space-y-2">
<div className="flex gap-0.5 overflow-x-auto pb-1">
{rows.map((h) => {
const hgt = Math.max(4, Math.round(((h.count || 0) / max) * 48));
return (
<div key={h.hour} className="flex w-5 shrink-0 flex-col items-center gap-1" title={`${h.label} · ${h.count} 条`}>
<div className="flex h-12 w-full items-end justify-center">
<div
className={`w-2 rounded-sm ${
h.is_current ? "bg-pink-400" : h.is_past ? "bg-white/20" : "bg-teal-400/70"
}`}
style={{ height: `${hgt}px` }}
/>
</div>
<div className={`text-[9px] ${(nowHour ?? -1) === h.hour ? "text-pink-300" : "text-slate-600"}`}>
{h.hour}
</div>
</div>
);
})}
</div>
<div className="max-h-40 space-y-1 overflow-y-auto">
{rows
.flatMap((h) => h.jobs || [])
.slice(0, 24)
.map((j) => (
<div
key={j.id}
className="flex items-center justify-between gap-2 rounded-lg border border-white/5 bg-black/20 px-2 py-1.5 text-[11px]"
>
<div className="min-w-0 truncate text-slate-300">
<span className="text-slate-500">{j.upload_at ? fmtTs(Number(j.upload_at)) : "—"}</span>
{" · "}
{j.anchor_name || "素材"}
{j.channel_name ? ` · ${j.channel_name}` : ""}
</div>
{j.can_upload_now && onUploadNow ? (
<button
type="button"
onClick={() => onUploadNow(j)}
className="shrink-0 rounded bg-pink-500/20 px-2 py-0.5 text-[10px] text-pink-200"
>
立即
</button>
) : (
<span className="shrink-0 text-slate-600">{j.status || ""}</span>
)}
</div>
))}
</div>
</div>
);
}