-
Notifications
You must be signed in to change notification settings - Fork 27
Barebones schedule timeline component #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { type EventType as Event } from "@/lib/types/events"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getClientTimeZone } from "@/lib/utils/client/shared"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import c from "config"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ReactNode } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const daysOfWeek = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Sunday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Monday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Tuesday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Wednesday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Thursday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Friday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Saturday", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function splitByDay(schedule: Event[]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const days: Map<string, Event[]> = new Map(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schedule.forEach((event) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const day = daysOfWeek[event.startTime.getDay()]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const existing = days.get(day); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (existing) existing.push(event); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else days.set(day, [event]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return days; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type DayHeaderProps = { dayName: string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const DefaultDayHeader = ({ dayName }: DayHeaderProps) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <tr key={dayName + " title"} className="border-b py-8"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <h2 className="w-full px-4 py-4 text-5xl font-black">{dayName}</h2> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </td> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </tr> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type RowProps = { event: Event; userTimeZone: string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function ScheduleTimelineBare({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schedule, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timezone, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DayHeader = DefaultDayHeader, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RenderEventRow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schedule: Event[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timezone?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DayHeader?: React.ComponentType<DayHeaderProps>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RenderEventRow: React.ComponentType<RowProps>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const userTimeZone = timezone ?? getClientTimeZone(c.hackathonTimezone); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const days = Array.from(splitByDay(schedule).entries()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="mx-auto mt-5 w-[99vw] lg:w-3/4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <table className="w-full"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <tbody> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {days.map( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ([dayName, arr]): ReactNode => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <DayHeader dayName={dayName} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {arr.map((event) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <RenderEventRow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key={event.id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event={event} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userTimeZone={userTimeZone} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing The shorthand fragment syntax 🐛 Proposed fix+import React from "react";Then update the render: {days.map(
- ([dayName, arr]): ReactNode => (
- <>
+ ([dayName, arr]) => (
+ <React.Fragment key={dayName}>
<DayHeader dayName={dayName} />
{arr.map((event) => (
<RenderEventRow
key={event.id}
event={event}
userTimeZone={userTimeZone}
/>
))}
- </>
+ </React.Fragment>
),
)}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </tbody> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </table> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: acmutsa/HackKit
Length of output: 13607
🏁 Script executed:
Repository: acmutsa/HackKit
Length of output: 3507
🏁 Script executed:
Repository: acmutsa/HackKit
Length of output: 1288
🏁 Script executed:
Repository: acmutsa/HackKit
Length of output: 2988
Convert
event.startTimeto aDatebefore calling.getDay().The
startTimefield is stored as an integer (milliseconds) in the database and typed asnumberby Drizzle ORM'stimestamp_msmode. Calling.getDay()directly will throw a runtime error. Convert it to a Date object first, as done elsewhere in the codebase (e.g., EventColumns.tsx):Suggested fix:
schedule.forEach((event) => { - const day = daysOfWeek[event.startTime.getDay()]; + const day = daysOfWeek[new Date(event.startTime).getDay()];📝 Committable suggestion
🤖 Prompt for AI Agents