-
Notifications
You must be signed in to change notification settings - Fork 5
Improve calendar event display + MUI TimePicker #173
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: main
Are you sure you want to change the base?
Changes from all commits
67ccab6
ec39000
6659257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,17 +6,29 @@ import { createViewWeek, CalendarConfig } from "@schedule-x/calendar"; | |||||||||||||||||||||||||
| import { createEventsServicePlugin } from "@schedule-x/events-service"; | ||||||||||||||||||||||||||
| import { useCalendarApp, ScheduleXCalendar } from "@schedule-x/react"; | ||||||||||||||||||||||||||
| import { Temporal } from "temporal-polyfill"; | ||||||||||||||||||||||||||
| import { TimePicker } from "@mui/x-date-pickers/TimePicker"; | ||||||||||||||||||||||||||
| import dayjs from "dayjs"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import "@schedule-x/theme-default/dist/index.css"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import "./css/planner.css"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const hasWeekendCourse = false; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function formatTime(date: Date): string { | ||||||||||||||||||||||||||
| return `${String(date.getHours()).padStart(2, "0")}:${String( | ||||||||||||||||||||||||||
| date.getMinutes(), | ||||||||||||||||||||||||||
| ).padStart(2, "0")}`; | ||||||||||||||||||||||||||
| /** Extract a concise room label from the raw newline-separated locations string. */ | ||||||||||||||||||||||||||
| function shortLocation(raw: string): string { | ||||||||||||||||||||||||||
| if (!raw) return ""; | ||||||||||||||||||||||||||
| const lines = raw | ||||||||||||||||||||||||||
| .split("\n") | ||||||||||||||||||||||||||
| .map((l) => l.trim()) | ||||||||||||||||||||||||||
| .filter(Boolean); | ||||||||||||||||||||||||||
| // room entries: "387 LINDE", "B280 MRE", "115c BAX", "240A CNRB" | ||||||||||||||||||||||||||
| const rooms = lines.filter((l) => /^[A-Z]?\d+\w*\s+[A-Z]/.test(l)); | ||||||||||||||||||||||||||
| if (rooms.length > 0) return rooms[0]; | ||||||||||||||||||||||||||
| // fall back to building codes (short all-caps tokens) | ||||||||||||||||||||||||||
| const buildings = lines.filter((l) => /^[A-Z]{2,}$/.test(l)); | ||||||||||||||||||||||||||
| if (buildings.length > 0) return buildings[0]; | ||||||||||||||||||||||||||
| return ""; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function TimeInput({ | ||||||||||||||||||||||||||
|
|
@@ -29,18 +41,30 @@ function TimeInput({ | |||||||||||||||||||||||||
| label: string; | ||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||
| <input | ||||||||||||||||||||||||||
| type="time" | ||||||||||||||||||||||||||
| className="planner-time-input" | ||||||||||||||||||||||||||
| aria-label={label} | ||||||||||||||||||||||||||
| value={formatTime(value)} | ||||||||||||||||||||||||||
| onChange={(e) => { | ||||||||||||||||||||||||||
| if (!e.target.value) return; | ||||||||||||||||||||||||||
| const [hours, minutes] = e.target.value.split(":").map(Number); | ||||||||||||||||||||||||||
| <TimePicker | ||||||||||||||||||||||||||
| value={dayjs(value)} | ||||||||||||||||||||||||||
| onChange={(newVal) => { | ||||||||||||||||||||||||||
| if (!newVal) return; | ||||||||||||||||||||||||||
| const day = new Date(value); | ||||||||||||||||||||||||||
| day.setHours(hours, minutes, 0, 0); | ||||||||||||||||||||||||||
| day.setHours(newVal.hour(), newVal.minute(), 0, 0); | ||||||||||||||||||||||||||
| onChange(day); | ||||||||||||||||||||||||||
|
Comment on lines
+46
to
50
Contributor
Author
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 dayjs MUI's
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||
| ampm={false} | ||||||||||||||||||||||||||
| slotProps={{ | ||||||||||||||||||||||||||
| textField: { | ||||||||||||||||||||||||||
| size: "small", | ||||||||||||||||||||||||||
| slotProps: { htmlInput: { "aria-label": label } }, | ||||||||||||||||||||||||||
| sx: { | ||||||||||||||||||||||||||
| width: "5.5rem", | ||||||||||||||||||||||||||
| "& .MuiInputBase-input": { | ||||||||||||||||||||||||||
| p: "4px 8px", | ||||||||||||||||||||||||||
| fontSize: "0.8rem", | ||||||||||||||||||||||||||
| textAlign: "center", | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| "& .MuiInputAdornment-root": { display: "none" }, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -66,7 +90,8 @@ function CourseToDates(courses: CourseStorage[]): DateData[] { | |||||||||||||||||||||||||
| for (const interval of day) { | ||||||||||||||||||||||||||
| dates.push({ | ||||||||||||||||||||||||||
| id: course.courseData.id, | ||||||||||||||||||||||||||
| title: course.courseData.number + " Section " + section.number, | ||||||||||||||||||||||||||
| title: course.courseData.number + " §" + section.number, | ||||||||||||||||||||||||||
| location: shortLocation(section.locations), | ||||||||||||||||||||||||||
|
Contributor
Author
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. 🚩 shortLocation always returns the first room for multi-location sections When a section has multiple newline-separated locations (e.g. Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
Author
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. Acknowledged — the location data format isn't a clean 1:1 zip with time entries. E.g., Ma 1a §1 has 3 time entries but 5 location lines ( |
||||||||||||||||||||||||||
| start: interval!.start, | ||||||||||||||||||||||||||
| end: interval!.end, | ||||||||||||||||||||||||||
| courseData: course.courseData, | ||||||||||||||||||||||||||
|
|
@@ -103,14 +128,26 @@ function courseColors(id: number) { | |||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function escapeHtml(s: string): string { | ||||||||||||||||||||||||||
| return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function toExternalEvents(calEvents: DateData[]) { | ||||||||||||||||||||||||||
| return calEvents.map((event, idx) => ({ | ||||||||||||||||||||||||||
| id: `${event.id}-${idx}`, | ||||||||||||||||||||||||||
| title: event.title, | ||||||||||||||||||||||||||
| start: toZonedDateTime(event.start), | ||||||||||||||||||||||||||
| end: toZonedDateTime(event.end), | ||||||||||||||||||||||||||
| calendarId: `course-${event.id}`, | ||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||
| return calEvents.map((event, idx) => { | ||||||||||||||||||||||||||
| const loc = event.location; | ||||||||||||||||||||||||||
| const html = loc | ||||||||||||||||||||||||||
| ? `<span class="sx-event-title">${escapeHtml(event.title)}</span><br/><span class="sx-event-location">${escapeHtml(loc)}</span>` | ||||||||||||||||||||||||||
| : `<span class="sx-event-title">${escapeHtml(event.title)}</span>`; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||
| id: `${event.id}-${idx}`, | ||||||||||||||||||||||||||
| title: event.title, | ||||||||||||||||||||||||||
| start: toZonedDateTime(event.start), | ||||||||||||||||||||||||||
| end: toZonedDateTime(event.end), | ||||||||||||||||||||||||||
| calendarId: `course-${event.id}`, | ||||||||||||||||||||||||||
| _customContent: { timeGrid: html }, | ||||||||||||||||||||||||||
|
Contributor
Author
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. 🚩 _customContent usage with Schedule-X v4 cannot be verified without node_modules The PR uses Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
Author
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. Verified locally — |
||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function ScheduleCalendar({ calEvents }: { calEvents: DateData[] }) { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,18 +12,20 @@ | |
| display: none; | ||
| } | ||
|
|
||
| .planner-time-input { | ||
| border: 1px solid lightgrey; | ||
| border-radius: 4px; | ||
| width: 100%; | ||
| min-width: 0; | ||
| max-width: 4.5rem; | ||
| text-align: center; | ||
| background-color: white; | ||
| font-size: 0.875rem; | ||
| line-height: 1.5; | ||
| /* custom event content */ | ||
| .sx-event-title { | ||
| font-weight: 600; | ||
| font-size: 0.75rem; | ||
| line-height: 1.2; | ||
| } | ||
|
|
||
| .planner-time-input::-webkit-calendar-picker-indicator { | ||
| .sx-event-location { | ||
| font-size: 0.65rem; | ||
| opacity: 0.8; | ||
| line-height: 1.2; | ||
| } | ||
|
|
||
| /* hide the default time label Schedule-X renders inside events */ | ||
| .sx__time-grid-event .sx__time-grid-event-time { | ||
| display: none; | ||
| } | ||
|
Comment on lines
+29
to
31
Contributor
Author
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. 📝 Info: CSS hides Schedule-X event time labels globally The rule Was this helpful? React with 👍 or 👎 to provide feedback. |
||
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.
📝 Info: The
shortLocationregex won't match rooms with multi-letter prefixesThe regex
/^[A-Z]?\d+\w*\s+[A-Z]/uses[A-Z]?which matches zero or one uppercase letter before the digits. Room codes with two-letter prefixes (e.g., "AB123 BUILDING") would not match. The comments indicate this is intentional based on the known data format ("387 LINDE", "B280 MRE", "115c BAX", "240A CNRB"), but if new room formats appear in the catalog, they would silently fall through to the building code fallback or return empty string — a graceful degradation rather than an error.Was this helpful? React with 👍 or 👎 to provide feedback.