Files
lst/frontend/src/routes/_app/(logistics)/-components/Grid.tsx
Blake Matthes 425f8f5f71 feat(frontend): migrated old > new silo adjustments
moved the apps around so we can use 1 url for cors bs
2025-10-25 17:22:51 -05:00

70 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 (
<ScrollArea className={`h-[80vh]`}>
<div
className="grid"
style={{
display: "grid",
gridTemplateColumns: `100px repeat(${days.length}, 350px)`, // each day = 180px wide
//minWidth: `${100 + days.length * 350}px`,
}}
>
{/* Empty top-left corner */}
<div className="sticky top-0 left-0 bg-background z-30"></div>
{/* Date headers */}
{days.map((d: any) => (
<div
key={d.toDateString()}
className="sticky top-0 bg-background z-20 p-2 font-semibold text-center"
>
{format(d, "EEEE M/d/yyyy")}
</div>
))}
{hours.map((hour) => (
<React.Fragment key={hour}>
<div className="border p-1 text-right text-sm">{hour}:00</div>
{days.map((d: any) => (
<div key={`${d}-${hour}`} className="relative border h-20">
{children && children(d, hour)}
</div>
))}
</React.Fragment>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
);
}