-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathScheduleTable.tsx
More file actions
146 lines (135 loc) · 3.35 KB
/
Copy pathScheduleTable.tsx
File metadata and controls
146 lines (135 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {
Table,
TableBody,
TableCell,
TableHeader,
TableRow,
} from "@/components/shadcn/ui/table";
import { type EventType as Event } from "@/lib/types/events";
import { ReactNode } from "react";
import { formatInTimeZone } from "date-fns-tz";
import c from "config";
import { Badge } from "@/components/shadcn/ui/badge";
import Link from "next/link";
const userTimeZone = c.hackathonTimezone;
function splitByDay(schedule: Event[]) {
const days: Map<string, Event[]> = new Map<string, Event[]>();
schedule.forEach((event) => {
const day = daysOfWeek[event.startTime.getDay()];
if (days.get(day)) {
days.get(day)?.push(event);
} else {
days.set(day, [event]);
}
});
return days;
}
type ScheduleTableProps = {
schedule: Event[];
};
const daysOfWeek = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
function eventDateString(arr: Event[], timezone: string) {
const date = formatInTimeZone(arr[0].startTime, timezone, "PPPP");
const retString = date.substring(0, date.length - 6);
return retString;
}
export default function ScheduleTable({
schedule,
}: ScheduleTableProps) {
return (
<div className="mx-auto mt-5 w-[99vw] lg:w-3/4">
<Table className="grid gap-6">
{Array.from(splitByDay(schedule).entries()).map(
([dateID, arr]): ReactNode => (
<>
<TableBody key={dateID} className="border">
<TableHeader className="flex justify-start">
<span className="m-1 p-4 text-center text-xl font-bold lg:text-4xl">
<p>{`${eventDateString(arr, userTimeZone)}`}</p>
</span>
</TableHeader>
{arr.map(
(event): ReactNode => (
<EventRow
key={event.id}
event={event}
/>
),
)}
</TableBody>
</>
),
)}
</Table>
</div>
);
}
// Needs timezone prop
type eventRowProps = {
event: Event;
};
export function EventRow({ event }: eventRowProps) {
const startTimeFormatted = formatInTimeZone(
event.startTime,
userTimeZone,
"hh:mm a",
{
useAdditionalDayOfYearTokens: true,
},
);
const endTimeFormatted = formatInTimeZone(
event.endTime,
userTimeZone,
"h:mm a",
);
const color = (c.eventTypes as Record<string, string>)[event.type];
const href = "/schedule/" + event.id;
return (
<TableRow
key={event.id}
className="flex flex-col justify-around bg-transparent px-4 pb-1 odd:bg-white/5"
>
<TableCell className="p-2 flex place-items-center">
<div className="w-1/3">
<Link href={href}>
<span className="flex font-semibold">
<p>{`${startTimeFormatted}`}</p>
<p className="hidden sm:contents">
{`- ${endTimeFormatted}`}
</p>
</span>
</Link>
</div>
<div className="flex w-2/3 place-items-center justify-end gap-2">
<Badge
variant={"outline"}
className="flex justify-center text-center lg:w-[5rem]"
style={{
borderColor: color,
}}
>
<p className="text-[0.5rem] lg:text-xs">{event.type}</p>
</Badge>
<Link href={href}>
<p className="p-1 text-right font-semibold lg:text-xl">
{`${event.title}`}
</p>
</Link>
</div>
</TableCell>
<TableCell className="hidden lg:contents">
<div className="p-2 w-full truncate text-ellipsis text-right">
<p>{`${event.description}`}</p>
</div>
</TableCell>
</TableRow>
);
}