1
0
Fork 0
polaris-task-force/src/components/frontend/baseManagement/ConstructionEta.tsx
Z8MB1E 5be390012a feat(base): timestamp-based construction lifecycle with progress panel
Blueprints declare constructionDurationMinutes instead of tick counts. Delivering the last material starts construction at delivery time via maybeStartConstruction, setting constructionStartedAt/CompletesAt on the site; the game tick only sweeps completed sites. Structure detail page extracts server data helpers and shows a ConstructionPanel with a literal ETA countdown.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-16 23:14:07 -04:00

33 lines
1 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
interface ConstructionEtaProps {
completesAt: string | Date | null;
}
function formatDuration(ms: number): string {
const totalSeconds = Math.max(0, Math.round(ms / 1000));
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
return `${minutes}m ${seconds}s`;
}
/**
* Live countdown to the site's exact constructionCompletesAt deadline.
*/
export function ConstructionEta({ completesAt }: ConstructionEtaProps) {
const [nowMs, setNowMs] = useState(() => Date.now());
useEffect(() => {
const timer = setInterval(() => setNowMs(Date.now()), 1000);
return () => clearInterval(timer);
}, []);
const deadline = completesAt ? new Date(completesAt).getTime() : NaN;
const remaining = Number.isFinite(deadline) ? deadline - nowMs : 0;
return <span>ETA {remaining <= 0 ? "any moment" : formatDuration(remaining)}</span>;
}