Skip to content

Commit 0f40fbd

Browse files
authored
fix: activity with no timeslot handling (#92)
1 parent 456649d commit 0f40fbd

File tree

4 files changed

+56
-30
lines changed

4 files changed

+56
-30
lines changed

src/components/Timetable.tsx

+37-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Timeslot = {
77
start_time: string;
88
end_time: string;
99
room: string;
10+
custom_name?: string;
1011
};
1112

1213
// Convert string representation "hh:mm" to minutes
@@ -15,9 +16,9 @@ function timeToMinutes(time: string) {
1516
return hours * 60 + minutes + seconds / 60;
1617
}
1718

18-
function Hours(props: { startTime: string; endTime: string }) {
19-
let startHour = timeToMinutes(props.startTime) / 60;
20-
const endHour = timeToMinutes(props.endTime) / 60;
19+
function Hours(props: { startTime: number; endTime: number }) {
20+
let startHour = props.startTime / 60;
21+
const endHour = props.endTime / 60;
2122
const numberOfHours = endHour - startHour;
2223

2324
let hours: any[] = [];
@@ -39,46 +40,48 @@ function Hours(props: { startTime: string; endTime: string }) {
3940
function TimeTableEvent(props: {
4041
timeslot: Timeslot;
4142
activity: ICBDActivity;
42-
startTime: string;
43-
endTime: string;
43+
startTime: number;
44+
endTime: number;
4445
}) {
4546
// In minutes
46-
const startTime = timeToMinutes(props.startTime);
47-
const endTime = timeToMinutes(props.endTime);
4847
const timeslot = props.timeslot;
4948
const tStartTime = timeToMinutes(timeslot.start_time);
5049
const tEndTime = timeToMinutes(timeslot.end_time);
5150

52-
const duration = endTime - startTime;
51+
const duration = props.endTime - props.startTime;
5352

5453
const size = (tEndTime - tStartTime) / duration;
5554

56-
const position = (tStartTime - startTime) / duration;
55+
const position = (tStartTime - props.startTime) / duration;
5756

5857
const style = { height: `calc(${size * 100}% - 0.4rem)` };
5958

6059
const router = useRouter();
6160

62-
const translation = getTranslation(props.activity, router.locale);
61+
const name =
62+
timeslot.custom_name ||
63+
getTranslation(props.activity, router.locale).name ||
64+
"";
6365

6466
return (
6567
<div
6668
className={styles.event}
69+
title={name}
6770
style={{
6871
top: `${position * 100}%`,
6972
backgroundColor: props.activity.color || "orange",
7073
...style,
7174
}}
7275
>
73-
<p>{translation.name || ""}</p>
76+
<p>{name}</p>
7477
</div>
7578
);
7679
}
7780

7881
function TimetableEntry(props: {
7982
timeslots: [Timeslot, ICBDActivity][];
80-
startTime: string;
81-
endTime: string;
83+
startTime: number;
84+
endTime: number;
8285
}) {
8386
let key = 0;
8487

@@ -99,21 +102,29 @@ function TimetableEntry(props: {
99102
);
100103
}
101104

102-
export function Timetable(props: {
103-
activities: ICBDActivity[];
104-
startTime: string;
105-
endTime: string;
106-
}) {
105+
export function Timetable(props: { activities: ICBDActivity[] }) {
107106
let rooms: Record<string, [Timeslot, ICBDActivity][]> = {};
108107

109108
let tt = useTranslationTable();
110109

110+
let startTime = 24 * 60;
111+
let endTime = 0;
112+
111113
props.activities.forEach((activity) => {
114+
if (!activity.timeslots) {
115+
return;
116+
}
117+
112118
const timeslots: Timeslot[] = JSON.parse(
113119
JSON.stringify(activity.timeslots)
114120
);
115121

116122
timeslots.forEach((timeslot) => {
123+
let tStartTime = timeToMinutes(timeslot.start_time);
124+
startTime = Math.min(tStartTime, startTime);
125+
let tEndTime = timeToMinutes(timeslot.end_time);
126+
endTime = Math.max(tEndTime, endTime);
127+
117128
let groupKey = timeslot.room;
118129
if (!rooms[groupKey]) {
119130
rooms[groupKey] = [];
@@ -122,6 +133,10 @@ export function Timetable(props: {
122133
});
123134
});
124135

136+
let hours = (endTime / 60).toString().padStart(2, "0");
137+
let minutes = (endTime % 60).toString().padStart(2, "0");
138+
let formattedEndTime = hours + ":" + minutes;
139+
125140
return (
126141
<>
127142
<table className={styles.table}>
@@ -136,21 +151,21 @@ export function Timetable(props: {
136151
</tr>
137152
<tr>
138153
<td className={styles.hours}>
139-
<Hours startTime={props.startTime} endTime={props.endTime} />
154+
<Hours startTime={startTime} endTime={endTime} />
140155
</td>
141156
{Object.keys(rooms).map((room) => (
142157
<td key={"entry|" + room}>
143158
<TimetableEntry
144159
timeslots={rooms[room]}
145-
startTime={props.startTime}
146-
endTime={props.endTime}
160+
startTime={startTime}
161+
endTime={endTime}
147162
/>
148163
</td>
149164
))}
150165
</tr>
151166
</tbody>
152167
</table>
153-
<p>{`${tt["icbd-end-of-event"]} ${props.endTime}`}</p>
168+
<p>{`${tt["icbd-end-of-event"]} ${formattedEndTime}`}</p>
154169
</>
155170
);
156171
}

src/pages/icbd.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ export default function ICBDPage(
176176

177177
<div className={pageStyle.main}>
178178
<h1>Timetable</h1>
179-
<Timetable
180-
activities={props.activities}
181-
startTime="10:00"
182-
endTime="18:00"
183-
/>
179+
<Timetable activities={props.activities} />
184180
</div>
185181

186182
<div className={style.activities}>

src/styles/Timetable.module.scss

+17-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,23 @@
8585

8686
p {
8787
color: white;
88-
text-align: center;
89-
font-weight: normal;
88+
text-align: left;
89+
text-transform: uppercase;
90+
font-weight: bold;
91+
font-size: 0.75rem;
92+
max-height: 80%;
93+
max-width: 80%;
94+
text-overflow: ellipsis;
95+
overflow: hidden;
96+
overflow-y: scroll;
97+
98+
/* Hide scrollbar for IE, Edge and Firefox */
99+
-ms-overflow-style: none; /* IE and Edge */
100+
scrollbar-width: none; /* Firefox */
101+
/* Hide scrollbar for Chrome, Safari and Opera */
102+
&::-webkit-scrollbar {
103+
display: none;
104+
}
90105
}
91106
}
92107
}

0 commit comments

Comments
 (0)