Compare commits

..

No commits in common. "6ba8adab5b981895d179f3c706cdbed9b105a99d" and "1804544203daa8e547996952bb6b734fa1de55f0" have entirely different histories.

4 changed files with 6 additions and 13 deletions

View file

@ -113,11 +113,6 @@ export function getInitialDraftSpeed(season: DraftSpeedSource): string {
return "standard";
}
/** Converts a millisecond duration to whole seconds, always rounding up. */
export function msToSeconds(ms: number): number {
return Math.max(0, Math.ceil(ms / 1000));
}
/**
* Anchors a server-provided remaining-seconds value to the local client clock.
* Use this everywhere we convert timeRemaining an expiresAt timestamp so the

View file

@ -42,7 +42,7 @@ import { useDraftNotifications } from "~/hooks/useDraftNotifications";
import { NotificationSettings } from "~/components/NotificationSettings";
import { AutodraftBadgeWithPopover, AutodraftSettings } from "~/components/AutodraftSettings";
import { toast } from "sonner";
import { clientExpiresAt, formatClockTime, getTimerColorClass, msToSeconds } from "~/lib/draft-timer";
import { clientExpiresAt, formatClockTime, getTimerColorClass } from "~/lib/draft-timer";
import { Users, LayoutGrid, ListChecks, Settings, ListOrdered } from "lucide-react";
import type { Route } from "./+types/$leagueId.draft.$seasonId";
@ -509,7 +509,7 @@ export default function DraftRoom() {
// without skew, then re-anchor to client clock.
const active = timers.find((t) => t.picksExpiresAt && t.picksExpiresAt.getTime() > loaderTimerNow);
if (!active?.picksExpiresAt) return null;
const secondsRemaining = msToSeconds(active.picksExpiresAt.getTime() - loaderTimerNow);
const secondsRemaining = Math.ceil((active.picksExpiresAt.getTime() - loaderTimerNow) / 1000);
return { teamId: active.teamId, expiresAt: clientExpiresAt(secondsRemaining) };
});
@ -517,7 +517,7 @@ export default function DraftRoom() {
if (!pickTimerExpiresAt) return;
const { teamId, expiresAt } = pickTimerExpiresAt;
const tick = () => {
const remaining = msToSeconds(expiresAt - Date.now());
const remaining = Math.max(0, Math.ceil((expiresAt - Date.now()) / 1000));
setTeamTimers((prev) => prev[teamId] === remaining ? prev : { ...prev, [teamId]: remaining });
};
tick(); // immediate update so display is accurate on mount

View file

@ -7,7 +7,6 @@ import { checkOvernightPause } from "./overnight-pause-check";
import { calculatePickInfo } from "~/models/draft-utils";
import { logger } from "./logger";
import { db } from "./db";
import { msToSeconds } from "~/lib/draft-timer";
// Socket event types
interface ServerToClientEvents {
@ -328,7 +327,7 @@ export function initializeSocketIO(httpServer: HTTPServer): SocketIOServer {
const expiresAt = t.picksExpiresAt?.getTime();
const computedRemaining =
expiresAt && expiresAt > nowMs
? msToSeconds(expiresAt - nowMs)
? Math.max(0, Math.floor((expiresAt - nowMs) / 1000))
: t.timeRemaining;
return {
teamId: t.teamId,

View file

@ -7,7 +7,6 @@ import { checkOvernightPause, evictOvernightPauseCache, overnightPauseCacheKeys,
import { logger } from "./logger";
import { db } from "./db";
import { startDraft } from "~/services/draft-autostart";
import { msToSeconds } from "~/lib/draft-timer";
// Per-season in-memory state
const pickTimeouts = new Map<string, NodeJS.Timeout>(); // seasonId → active setTimeout
@ -260,7 +259,7 @@ async function _schedulePickForSeason(seasonId: string): Promise<void> {
}
const msUntilExpiry = expiresAt.getTime() - now;
const timeRemaining = msToSeconds(msUntilExpiry);
const timeRemaining = Math.max(0, Math.ceil(msUntilExpiry / 1000));
// Tell clients to start their local countdown.
try {
@ -428,7 +427,7 @@ export async function onDraftPaused(seasonId: string): Promise<Array<{ teamId: s
activeTimers
.filter((t) => t.picksExpiresAt !== null)
.map(async (timer) => {
const remaining = msToSeconds((timer.picksExpiresAt?.getTime() ?? now) - now);
const remaining = Math.max(0, Math.floor(((timer.picksExpiresAt?.getTime() ?? now) - now) / 1000));
await db
.update(schema.draftTimers)
.set({ timeRemaining: remaining, picksExpiresAt: null, picksStartedAt: null, updatedAt: new Date() })