// src/routes/traffic/Grid.tsx import { format } from "date-fns"; import React from "react"; import { ScrollArea, ScrollBar } from "../../../components/ui/scroll-area"; export const days = Array.from( { length: 5 }, (_, i) => new Date(Date.now() + i * 24 * 60 * 60 * 1000), ); // the layout of the hours const hoursBefore = 3; const totalHours = 24; // get the current hour const currentHour = new Date().getHours(); const startHour = (currentHour - hoursBefore + 24) % 24; // generate the hours array const hours = Array.from( { length: totalHours }, (_, i) => (startHour + i) % 24, ); export function Grid({ days, children, }: { days: any; children?: (day: Date, hour: number) => React.ReactNode; }) { return (
{/* Empty top-left corner */}
{/* Date headers */} {days.map((d: any) => (
{format(d, "EEEE M/d/yyyy")}
))} {hours.map((hour) => (
{hour}:00
{days.map((d: any) => (
{children && children(d, hour)}
))}
))}
); }