Skip to content

Commit 6560fe2

Browse files
authored
Merge pull request #10 from codersforcauses/fix-schedule-page-bugs
Fix schedule page bugs
2 parents 698221c + 3f0a564 commit 6560fe2

8 files changed

Lines changed: 651 additions & 262 deletions

File tree

client/src/components/time_indicator.tsx

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,68 @@ import {
33
getVisibleTimetableRect,
44
} from "@/components/timetable";
55

6+
/*
7+
Resizes the time indicator to the correct width and positions it at the
8+
y-position corresponding to the current time.
9+
*/
610
export function resizeAndPositionTimeIndicator() {
711
const time_indicator = document.getElementById("time-indicator");
812
if (time_indicator == null) return;
913

1014
const now_label = document.getElementById("time-indicator-label");
1115
if (now_label == null) return;
1216

17+
const separator_rect = document
18+
.getElementById("timetable-separator")
19+
?.getBoundingClientRect();
20+
if (separator_rect == undefined) return;
21+
22+
const content_rect = document
23+
.getElementById("timetable-content")
24+
?.getBoundingClientRect();
25+
if (content_rect == undefined) return;
26+
1327
const visible = getVisibleTimetableRect();
1428
if (visible == undefined) return;
1529

16-
time_indicator.style.width = visible.width + "px";
17-
time_indicator.style.left = visible.left + "px";
18-
1930
const now = new Date(Date.now());
2031
const hour = now.getHours();
2132
const mins = now.getMinutes();
2233

23-
const top = getTimeTopPosition(hour, mins);
24-
if (top == undefined) return;
25-
time_indicator.style.top = top + "px";
34+
const time_top = getTimeTopPosition(hour, mins);
35+
if (time_top == undefined) return;
36+
37+
time_indicator.style.left =
38+
visible.left - separator_rect.width - content_rect.left + "px";
39+
time_indicator.style.top = time_top - content_rect.top + "px";
40+
time_indicator.style.width = visible.width + separator_rect.width + "px";
2641

2742
const now_label_rect = now_label.getBoundingClientRect();
2843
if (now_label_rect == undefined) return;
2944

30-
const now_label_left = visible.left - now_label_rect.width;
31-
const now_label_top = top - now_label_rect.height / 2;
32-
now_label.style.left = now_label_left + "px";
33-
now_label.style.top = now_label_top + "px";
34-
35-
if (top < visible.top || top > visible.bottom) {
36-
time_indicator.style.display = "none";
37-
now_label.style.display = "none";
38-
} else {
39-
time_indicator.style.display = "inline";
40-
now_label.style.display = "inline";
41-
}
45+
const now_label_left =
46+
visible.left - now_label_rect.width - separator_rect.width;
47+
const now_label_top = time_top - now_label_rect.height / 2;
48+
49+
const parent_rect = time_indicator.parentElement?.getBoundingClientRect();
50+
if (parent_rect == undefined) return;
51+
52+
now_label.style.left = now_label_left - parent_rect.left + "px";
53+
now_label.style.top = now_label_top - parent_rect.top + "px";
4254
}
4355

56+
/*
57+
Component consisting of a rounded label containing the text "Now" and a 2px
58+
thick line stretching across the visible area of the timetable.
59+
60+
There should only be one TimeIndicator per page.
61+
*/
4462
function TimeIndicator() {
4563
return (
4664
<>
4765
<div
4866
id="time-indicator-label"
49-
className="absolute z-[1000] h-fit w-fit rounded-full bg-slate-400 p-1 pl-2 pr-2"
67+
className="absolute z-[100] h-fit w-fit rounded-full bg-slate-400 p-1 pl-2 pr-2"
5068
>
5169
<p className="text-slate-100">Now</p>
5270
</div>

client/src/components/time_tag.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { getDurationMinutes } from "@/components/timetable";
22

3+
/*
4+
@prop start_time: string of form HH:MM:SS containing the start time to display
5+
@prop end_time: string of form HH:MM:SS containing the end time to display
6+
@prop display: (optional) string describing what to display in the tag,
7+
defaults to displaying the start and end times, "duration" to display duration,
8+
or "both" to display start and end times with duration in brackets.
9+
*/
310
interface TimeTagProps {
411
start_time: string;
512
end_time: string;
613
display?: string;
714
}
815

16+
/*
17+
A small round tag containing a clock icon and either the start and end times,
18+
the duration, or both, specified by the display prop.
19+
*/
920
function TimeTag({ start_time, end_time, display }: TimeTagProps) {
1021
const time_string =
1122
start_time.substring(0, 5) + "-" + end_time.substring(0, 5);

0 commit comments

Comments
 (0)