brackt/app/components/sport-season/EventSchedule.tsx
Chris Parsons e2b178221a
Add oxlint linting setup with zero errors (#194)
* Add oxlint and fix all lint errors

- Install oxlint, add .oxlintrc.json with rules for TypeScript/React
- Add npm run lint / lint:fix scripts
- Add Claude PostToolUse hook to run oxlint on every edited file
- Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array
- Fix no-array-index-key (use stable keys or suppress positional cases)
- Fix exhaustive-deps missing dependency in useEffect
- Promote exhaustive-deps and no-array-index-key to errors
- Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix no-explicit-any warnings and upgrade tsconfig to ES2023

- Replace all `any` types with proper types or `unknown` across ~20 files
- Add typed socket payload interfaces in draft route and useDraftSocket
- Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch)
- Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed
- Fix cascading type errors uncovered by removing any: Map.get narrowing,
  participant relation types, ChartDataPoint, Partial<NewSeason> indexing
- Add ParticipantResultWithParticipant type to participant-result model
- Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult)
- Fix duplicate getQPStandings import in sportsSeasonId.server.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Promote no-explicit-any to error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00

175 lines
6.1 KiB
TypeScript

import { format, parseISO } from "date-fns";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Badge } from "~/components/ui/badge";
import { Calendar, CheckCircle2, Clock } from "lucide-react";
interface ScheduleEvent {
id: string;
name: string;
eventDate: string | null;
eventStartsAt?: Date | string | null;
eventType: string;
isComplete: boolean;
completedAt?: Date | string | null;
}
interface EventScheduleProps {
upcomingEvents: ScheduleEvent[];
recentEvents: ScheduleEvent[];
}
function formatEventDate(dateStr: string | null | undefined): string {
if (!dateStr) return "Date TBD";
try {
// eventDate is stored as a date string "YYYY-MM-DD"
return format(parseISO(dateStr), "MMM d, yyyy");
} catch {
return dateStr;
}
}
/**
* Returns the display date for an event.
* Prefers eventStartsAt (a full UTC timestamp → correct local date) over
* eventDate (the UTC calendar date, which is off by one day for late-night
* events in UTC-negative timezones like PDT).
*/
function getDisplayDate(event: Pick<ScheduleEvent, "eventDate" | "eventStartsAt">): string {
if (event.eventStartsAt) {
const d = new Date(event.eventStartsAt);
if (!isNaN(d.getTime())) {
return format(d, "MMM d, yyyy");
}
}
return formatEventDate(event.eventDate);
}
function getEventTypeLabel(eventType: string): string {
switch (eventType) {
case "playoff_game":
return "Bracket";
case "major_tournament":
return "Major";
case "final_standings":
return "Final Standings";
case "schedule_event":
return "Non-Scoring";
default:
return eventType;
}
}
export function EventSchedule({ upcomingEvents, recentEvents }: EventScheduleProps) {
const hasUpcoming = upcomingEvents.length > 0;
const hasRecent = recentEvents.length > 0;
if (!hasUpcoming && !hasRecent) return null;
return (
<div className="grid gap-4 sm:grid-cols-2">
{/* Upcoming Events */}
{hasUpcoming && (
<Card className="border-electric/20">
<CardHeader className="pb-3">
<CardTitle className="text-sm font-medium flex items-center gap-2 text-electric">
<Clock className="h-4 w-4" />
Upcoming
</CardTitle>
</CardHeader>
<CardContent className="pt-0">
<ul className="space-y-3">
{upcomingEvents.map((event, index) => (
<li
key={event.id}
className={`flex items-start justify-between gap-2 ${
index === 0 ? "" : "border-t pt-3"
}`}
>
<div className="min-w-0">
<p
className={`text-sm font-medium truncate ${
index === 0 ? "text-foreground" : "text-muted-foreground"
}`}
>
{index === 0 && (
<span className="inline-block w-1.5 h-1.5 rounded-full bg-electric mr-2 mb-0.5" />
)}
{event.name}
</p>
<p className="text-xs text-muted-foreground flex items-center gap-1 mt-0.5">
<Calendar className="h-3 w-3" />
<span suppressHydrationWarning>{getDisplayDate(event)}</span>
{event.eventStartsAt && (
<span suppressHydrationWarning>
· {format(new Date(event.eventStartsAt), "h:mm a")}
</span>
)}
</p>
</div>
{event.eventType === "schedule_event" ? (
!event.isComplete && (() => {
const isPast = event.eventStartsAt
? new Date(event.eventStartsAt) < new Date()
: event.eventDate !== null && event.eventDate < new Date().toISOString().split("T")[0];
return isPast && (
<Badge variant="outline" className="text-xs shrink-0 border-amber-500/30 text-amber-400">
Results Pending
</Badge>
);
})()
) : (
<Badge variant="outline" className="text-xs shrink-0">
{getEventTypeLabel(event.eventType)}
</Badge>
)}
</li>
))}
</ul>
</CardContent>
</Card>
)}
{/* Recent Results */}
{hasRecent && (
<Card className="border-emerald-500/20">
<CardHeader className="pb-3">
<CardTitle className="text-sm font-medium flex items-center gap-2 text-emerald-400">
<CheckCircle2 className="h-4 w-4" />
Recent Results
</CardTitle>
</CardHeader>
<CardContent className="pt-0">
<ul className="space-y-3">
{recentEvents.map((event, index) => (
<li
key={event.id}
className={`flex items-start justify-between gap-2 ${
index === 0 ? "" : "border-t pt-3"
}`}
>
<div className="min-w-0">
<p className="text-sm font-medium text-muted-foreground truncate">
{event.name}
</p>
<p className="text-xs text-muted-foreground flex items-center gap-1 mt-0.5">
<Calendar className="h-3 w-3" />
<span suppressHydrationWarning>{getDisplayDate(event)}</span>
</p>
</div>
{event.eventType !== "schedule_event" && (
<Badge
variant="outline"
className="text-xs shrink-0 border-emerald-500/30 text-emerald-400"
>
Done
</Badge>
)}
</li>
))}
</ul>
</CardContent>
</Card>
)}
</div>
);
}