@@ -10,14 +10,17 @@ import { formatInterval, formatTime, parseTime, serializeTime } from "../utils";
10
10
11
11
import InfoIcon from "../../../../static/frontend/img/info.svg" ;
12
12
import XIcon from "../../../../static/frontend/img/x.svg" ;
13
- import { useMatcherConfigMutation , useMatcherSlotsMutation } from "../../../utils/queries/matcher" ;
13
+ import { useMatcherSlotsMutation } from "../../../utils/queries/matcher" ;
14
+
15
+ const DEFAULT_LOCATION = "TBD" ;
14
16
15
17
interface TileDetails {
16
18
days : string [ ] ;
17
19
daysLinked : boolean ;
18
20
startTime : number ;
19
21
endTime : number ;
20
22
length : number ;
23
+ location : string ;
21
24
}
22
25
23
26
interface CreateStageProps {
@@ -61,15 +64,15 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
61
64
daysLinked : true ,
62
65
startTime : - 1 ,
63
66
endTime : - 1 ,
64
- length : 60
67
+ length : 60 ,
68
+ location : DEFAULT_LOCATION
65
69
} ) ;
66
70
67
71
/**
68
72
* Whether or not anything has been edited
69
73
*/
70
74
const [ edited , setEdited ] = useState < boolean > ( false ) ;
71
75
72
- const matcherConfigMutation = useMatcherConfigMutation ( profile . courseId ) ;
73
76
const matcherSlotsMutation = useMatcherSlotsMutation ( profile . courseId ) ;
74
77
75
78
/**
@@ -87,7 +90,8 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
87
90
startTime : React . createRef < HTMLInputElement > ( ) ,
88
91
endTime : React . createRef < HTMLInputElement > ( ) ,
89
92
length : React . createRef < HTMLInputElement > ( ) ,
90
- toggle : React . createRef < HTMLInputElement > ( )
93
+ toggle : React . createRef < HTMLInputElement > ( ) ,
94
+ location : React . createRef < HTMLInputElement > ( )
91
95
} ;
92
96
93
97
/**
@@ -114,7 +118,8 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
114
118
startTime : t ,
115
119
endTime : t + tileDetails . length ,
116
120
// linked only if there are multiple days and user wants to link them
117
- isLinked : tileDetails . daysLinked && tileDetails . days . length > 1
121
+ isLinked : tileDetails . daysLinked && tileDetails . days . length > 1 ,
122
+ location : tileDetails . location
118
123
} ) ;
119
124
}
120
125
}
@@ -130,7 +135,8 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
130
135
const times = slot . times . map ( time => ( {
131
136
day : time . day ,
132
137
startTime : serializeTime ( time . startTime ) ,
133
- endTime : serializeTime ( time . endTime )
138
+ endTime : serializeTime ( time . endTime ) ,
139
+ location : time . location
134
140
} ) ) ;
135
141
return {
136
142
...slot ,
@@ -254,6 +260,22 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
254
260
setCurCreatedTimes ( newTimes ) ;
255
261
} ;
256
262
263
+ /**
264
+ * Edit the location field of an event
265
+ *
266
+ * @param index index of time to edit
267
+ * @param newLocation new location value
268
+ */
269
+ const editTime_location = ( index : number , newLocation : string ) => {
270
+ const newTimes = [ ...curCreatedTimes ] ;
271
+ if ( newLocation . trim ( ) === "" ) {
272
+ newTimes [ index ] [ "location" ] = DEFAULT_LOCATION ;
273
+ } else {
274
+ newTimes [ index ] [ "location" ] = newLocation ;
275
+ }
276
+ setCurCreatedTimes ( newTimes ) ;
277
+ } ;
278
+
257
279
const toggleCreatingTiledEvents = ( e : React . ChangeEvent < HTMLInputElement > ) : void => {
258
280
// current value of checkbox after click
259
281
const checked = e . target . checked ;
@@ -297,6 +319,10 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
297
319
setTileDetails ( { ...tileDetails , daysLinked : e . target . checked } ) ;
298
320
} ;
299
321
322
+ const editTiled_location = ( value : string ) : void => {
323
+ setTileDetails ( { ...tileDetails , location : value } ) ;
324
+ } ;
325
+
300
326
const saveTiledEvents = ( ) => {
301
327
const newSlots = [ ] ;
302
328
for ( let t = tileDetails . startTime ; t <= tileDetails . endTime - tileDetails . length ; t += tileDetails . length ) {
@@ -307,17 +333,28 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
307
333
day : day ,
308
334
startTime : t ,
309
335
endTime : t + tileDetails . length ,
310
- isLinked : tileDetails . days . length > 1
336
+ isLinked : tileDetails . days . length > 1 ,
337
+ location : tileDetails . location
311
338
} ) ;
312
339
}
313
340
newSlots . push ( newEvent ) ;
314
341
} else {
315
342
for ( const day of tileDetails . days ) {
316
- newSlots . push ( { times : [ { day : day , startTime : t , endTime : t + tileDetails . length , isLinked : false } ] } ) ;
343
+ newSlots . push ( {
344
+ times : [
345
+ {
346
+ day : day ,
347
+ startTime : t ,
348
+ endTime : t + tileDetails . length ,
349
+ isLinked : false ,
350
+ location : tileDetails . location
351
+ }
352
+ ]
353
+ } ) ;
317
354
}
318
355
}
319
356
}
320
- setSlots ( [ ...slots , ...newSlots ] ) ;
357
+ setSlots ( [ ...slots , ...newSlots ] as Slot [ ] ) ;
321
358
// stop creating tiled events
322
359
tileRefs . toggle . current ! . checked = false ;
323
360
toggleCreatingTiledEvents ( { target : tileRefs . toggle . current ! } as React . ChangeEvent < HTMLInputElement > ) ;
@@ -327,7 +364,7 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
327
364
* Save the newly created event and times
328
365
*/
329
366
const saveEvent = ( ) => {
330
- const newEvent = { times : curCreatedTimes } ;
367
+ const newEvent : Slot = { times : curCreatedTimes } ;
331
368
setSlots ( [ ...slots , newEvent ] ) ;
332
369
setCurCreatedTimes ( [ ] ) ;
333
370
setSavedExistingEvent ( null ) ;
@@ -340,7 +377,7 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
340
377
*/
341
378
const cancelEvent = ( ) => {
342
379
if ( savedExistingEvent !== null ) {
343
- setSlots ( [ ...slots , savedExistingEvent ] ) ;
380
+ setSlots ( [ ...slots , savedExistingEvent ] as Slot [ ] ) ;
344
381
setSavedExistingEvent ( null ) ;
345
382
}
346
383
// proceed with resetting current event
@@ -472,6 +509,16 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
472
509
/>
473
510
mins
474
511
</ div >
512
+ < div className = "matcher-tiling-location-container" >
513
+ < div className = "matcher-tiling-subheader" > Location:</ div >
514
+ < input
515
+ className = "matcher-tiling-locatoin-input"
516
+ type = "text"
517
+ ref = { tileRefs . location }
518
+ defaultValue = { tileDetails . location }
519
+ onChange = { e => editTiled_location ( e . target . value ) }
520
+ />
521
+ </ div >
475
522
</ div >
476
523
</ div >
477
524
< div className = "matcher-sidebar-tiling-bottom" >
@@ -494,32 +541,43 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
494
541
< XIcon className = "icon matcher-remove-time-icon" onClick = { ( ) => deleteTime ( time_idx ) } />
495
542
</ div >
496
543
< div className = "matcher-created-time" >
497
- < select
498
- defaultValue = { time . day }
499
- key = { `day_${ time_idx } /${ selectedEventIndices } ` }
500
- onChange = { e => editTime_day ( time_idx , e . target . value ) }
501
- >
502
- { DAYS . map ( day => (
503
- < option key = { day } value = { day } >
504
- { DAYS_ABBREV [ day ] }
505
- </ option >
506
- ) ) }
507
- </ select >
508
- < input
509
- type = "time"
510
- key = { `start_${ time_idx } /${ selectedEventIndices } ` }
511
- defaultValue = { serializeTime ( time . startTime ) }
512
- step = "900"
513
- onChange = { e => editTime_startTime ( time_idx , e . target . value ) }
514
- />
515
- –
516
- < input
517
- type = "time"
518
- key = { `end_${ time_idx } /${ selectedEventIndices } ` }
519
- defaultValue = { serializeTime ( time . endTime ) }
520
- step = "900"
521
- onChange = { e => editTime_endTime ( time_idx , e . target . value ) }
522
- />
544
+ < div className = "matcher-created-time-detail" >
545
+ < select
546
+ defaultValue = { time . day }
547
+ key = { `day_${ time_idx } /${ selectedEventIndices } ` }
548
+ onChange = { e => editTime_day ( time_idx , e . target . value ) }
549
+ >
550
+ { DAYS . map ( day => (
551
+ < option key = { day } value = { day } >
552
+ { DAYS_ABBREV [ day ] }
553
+ </ option >
554
+ ) ) }
555
+ </ select >
556
+ < input
557
+ type = "time"
558
+ key = { `start_${ time_idx } /${ selectedEventIndices } ` }
559
+ defaultValue = { serializeTime ( time . startTime ) }
560
+ step = "900"
561
+ onChange = { e => editTime_startTime ( time_idx , e . target . value ) }
562
+ />
563
+ –
564
+ < input
565
+ type = "time"
566
+ key = { `end_${ time_idx } /${ selectedEventIndices } ` }
567
+ defaultValue = { serializeTime ( time . endTime ) }
568
+ step = "900"
569
+ onChange = { e => editTime_endTime ( time_idx , e . target . value ) }
570
+ />
571
+ </ div >
572
+ < div className = "matcher-created-time-location" >
573
+ < span > Location:</ span >
574
+ < input
575
+ type = "text"
576
+ key = { `location_${ time_idx } /${ selectedEventIndices } ` }
577
+ defaultValue = { time . location }
578
+ onChange = { e => editTime_location ( time_idx , e . target . value ) }
579
+ />
580
+ </ div >
523
581
</ div >
524
582
</ div >
525
583
) ) }
@@ -558,6 +616,8 @@ export function CreateStage({ profile, initialSlots, nextStage }: CreateStagePro
558
616
< span className = "matcher-selected-time" >
559
617
{ time . day } { formatTime ( time . startTime ) } –{ formatTime ( time . endTime ) }
560
618
</ span >
619
+ < br />
620
+ < span className = "matcher-selected-location" > (location: { time . location } )</ span >
561
621
</ li >
562
622
) ) }
563
623
</ ul >
0 commit comments