videogen/apps/web/components/calendar/CalendarEntryPill.tsx
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

95 lines
3.5 KiB
TypeScript

"use client";
import * as React from "react";
import { GripVertical } from "lucide-react";
import { isCancelableSchedule } from "@/lib/types";
import type { CalendarEntry } from "@/lib/calendar";
import { cn } from "@/lib/utils";
import { ENTRY_DRAG_TYPE } from "@/components/calendar/calendar-month";
import { entryStatusStyle } from "@/components/calendar/entry-status";
import { platformLabel } from "@/components/schedule/platforms";
export interface CalendarEntryPillProps {
entry: CalendarEntry;
/** Fired when a still-pending entry is clicked (opens the reschedule control). */
onSelect: (entry: CalendarEntry) => void;
/** True while this entry's drag-drop move is in flight (spinner, no further drag). */
moving?: boolean;
}
/** Short local time label (e.g. "9:30 AM") for an ISO instant. */
function formatTime(iso: string | null): string {
if (!iso) return "";
const ms = new Date(iso).getTime();
if (Number.isNaN(ms)) return "";
return new Date(ms).toLocaleTimeString(undefined, {
hour: "numeric",
minute: "2-digit",
});
}
/**
* A single entry inside a day cell: a small colour-coded pill showing the local
* publish time and its first target platform. A still-`pending` entry is a
* button that opens the reschedule control; anything already run (or otherwise
* non-pending) renders as static, non-interactive text.
*/
export function CalendarEntryPill({
entry,
onSelect,
moving = false,
}: Readonly<CalendarEntryPillProps>) {
const style = entryStatusStyle(entry.status);
const time = formatTime(entry.scheduled_at);
const reschedulable = isCancelableSchedule(entry.status);
const firstPlatform = entry.platforms[0];
const platform = firstPlatform ? platformLabel(firstPlatform) : "";
const extra =
entry.platforms.length > 1 ? ` +${entry.platforms.length - 1}` : "";
const label = [time, platform && `· ${platform}${extra}`]
.filter(Boolean)
.join(" ");
const title = `${style.label}${time ? ` — ${time}` : ""}${
platform ? ` · ${entry.platforms.map(platformLabel).join(", ")}` : ""
}`;
const base =
"flex w-full min-w-0 items-center gap-1 rounded px-1.5 py-0.5 text-left text-[11px] font-medium leading-tight";
if (reschedulable) {
return (
<button
type="button"
draggable={!moving}
title={`${title} — drag to another day, or click to pick a time`}
aria-label={`${title}. Press Enter to reschedule.`}
onClick={() => onSelect(entry)}
onDragStart={(e) => {
e.dataTransfer.setData(ENTRY_DRAG_TYPE, entry.id);
e.dataTransfer.effectAllowed = "move";
}}
className={cn(
base,
style.pill,
"cursor-grab transition-colors active:cursor-grabbing focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
moving && "opacity-70",
)}
>
<GripVertical className="size-3 shrink-0 opacity-60" aria-hidden />
<span className={cn("size-1.5 shrink-0 rounded-full", style.dot)} aria-hidden />
<span className="truncate">{label || style.label}</span>
{moving && (
<span className="ml-auto size-3 shrink-0 animate-spin rounded-full border-2 border-current border-t-transparent" aria-hidden />
)}
</button>
);
}
return (
<span title={title} className={cn(base, style.pill, "cursor-default")}>
<span className={cn("size-1.5 shrink-0 rounded-full", style.dot)} aria-hidden />
<span className="truncate">{label || style.label}</span>
</span>
);
}