@@ -7,6 +7,7 @@ type Timeslot = {
7
7
start_time : string ;
8
8
end_time : string ;
9
9
room : string ;
10
+ custom_name ?: string ;
10
11
} ;
11
12
12
13
// Convert string representation "hh:mm" to minutes
@@ -15,9 +16,9 @@ function timeToMinutes(time: string) {
15
16
return hours * 60 + minutes + seconds / 60 ;
16
17
}
17
18
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 ;
21
22
const numberOfHours = endHour - startHour ;
22
23
23
24
let hours : any [ ] = [ ] ;
@@ -39,46 +40,48 @@ function Hours(props: { startTime: string; endTime: string }) {
39
40
function TimeTableEvent ( props : {
40
41
timeslot : Timeslot ;
41
42
activity : ICBDActivity ;
42
- startTime : string ;
43
- endTime : string ;
43
+ startTime : number ;
44
+ endTime : number ;
44
45
} ) {
45
46
// In minutes
46
- const startTime = timeToMinutes ( props . startTime ) ;
47
- const endTime = timeToMinutes ( props . endTime ) ;
48
47
const timeslot = props . timeslot ;
49
48
const tStartTime = timeToMinutes ( timeslot . start_time ) ;
50
49
const tEndTime = timeToMinutes ( timeslot . end_time ) ;
51
50
52
- const duration = endTime - startTime ;
51
+ const duration = props . endTime - props . startTime ;
53
52
54
53
const size = ( tEndTime - tStartTime ) / duration ;
55
54
56
- const position = ( tStartTime - startTime ) / duration ;
55
+ const position = ( tStartTime - props . startTime ) / duration ;
57
56
58
57
const style = { height : `calc(${ size * 100 } % - 0.4rem)` } ;
59
58
60
59
const router = useRouter ( ) ;
61
60
62
- const translation = getTranslation ( props . activity , router . locale ) ;
61
+ const name =
62
+ timeslot . custom_name ||
63
+ getTranslation ( props . activity , router . locale ) . name ||
64
+ "" ;
63
65
64
66
return (
65
67
< div
66
68
className = { styles . event }
69
+ title = { name }
67
70
style = { {
68
71
top : `${ position * 100 } %` ,
69
72
backgroundColor : props . activity . color || "orange" ,
70
73
...style ,
71
74
} }
72
75
>
73
- < p > { translation . name || "" } </ p >
76
+ < p > { name } </ p >
74
77
</ div >
75
78
) ;
76
79
}
77
80
78
81
function TimetableEntry ( props : {
79
82
timeslots : [ Timeslot , ICBDActivity ] [ ] ;
80
- startTime : string ;
81
- endTime : string ;
83
+ startTime : number ;
84
+ endTime : number ;
82
85
} ) {
83
86
let key = 0 ;
84
87
@@ -99,21 +102,29 @@ function TimetableEntry(props: {
99
102
) ;
100
103
}
101
104
102
- export function Timetable ( props : {
103
- activities : ICBDActivity [ ] ;
104
- startTime : string ;
105
- endTime : string ;
106
- } ) {
105
+ export function Timetable ( props : { activities : ICBDActivity [ ] } ) {
107
106
let rooms : Record < string , [ Timeslot , ICBDActivity ] [ ] > = { } ;
108
107
109
108
let tt = useTranslationTable ( ) ;
110
109
110
+ let startTime = 24 * 60 ;
111
+ let endTime = 0 ;
112
+
111
113
props . activities . forEach ( ( activity ) => {
114
+ if ( ! activity . timeslots ) {
115
+ return ;
116
+ }
117
+
112
118
const timeslots : Timeslot [ ] = JSON . parse (
113
119
JSON . stringify ( activity . timeslots )
114
120
) ;
115
121
116
122
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
+
117
128
let groupKey = timeslot . room ;
118
129
if ( ! rooms [ groupKey ] ) {
119
130
rooms [ groupKey ] = [ ] ;
@@ -122,6 +133,10 @@ export function Timetable(props: {
122
133
} ) ;
123
134
} ) ;
124
135
136
+ let hours = ( endTime / 60 ) . toString ( ) . padStart ( 2 , "0" ) ;
137
+ let minutes = ( endTime % 60 ) . toString ( ) . padStart ( 2 , "0" ) ;
138
+ let formattedEndTime = hours + ":" + minutes ;
139
+
125
140
return (
126
141
< >
127
142
< table className = { styles . table } >
@@ -136,21 +151,21 @@ export function Timetable(props: {
136
151
</ tr >
137
152
< tr >
138
153
< td className = { styles . hours } >
139
- < Hours startTime = { props . startTime } endTime = { props . endTime } />
154
+ < Hours startTime = { startTime } endTime = { endTime } />
140
155
</ td >
141
156
{ Object . keys ( rooms ) . map ( ( room ) => (
142
157
< td key = { "entry|" + room } >
143
158
< TimetableEntry
144
159
timeslots = { rooms [ room ] }
145
- startTime = { props . startTime }
146
- endTime = { props . endTime }
160
+ startTime = { startTime }
161
+ endTime = { endTime }
147
162
/>
148
163
</ td >
149
164
) ) }
150
165
</ tr >
151
166
</ tbody >
152
167
</ table >
153
- < p > { `${ tt [ "icbd-end-of-event" ] } ${ props . endTime } ` } </ p >
168
+ < p > { `${ tt [ "icbd-end-of-event" ] } ${ formattedEndTime } ` } </ p >
154
169
</ >
155
170
) ;
156
171
}
0 commit comments