1+ import type { Sessions } from 'app/App'
12import { AddIcon , DeleteIcon } from 'app/FeatherIcons'
23import formStyles from 'app/Form.module.css'
34import { SessionName } from 'app/SessionName'
@@ -10,6 +11,7 @@ type AddSession = {
1011 hour : string
1112 minute : string
1213 url : string
14+ track : string
1315}
1416
1517const toNumber = ( n : string ) => {
@@ -31,15 +33,16 @@ export const Editor = ({
3133} : {
3234 conferenceDate : string
3335 eventTimezoneName : string
34- sessions : { [ key : number ] : string }
36+ sessions : Sessions
3537 onAdd : ( newSession : AddSession ) => void
36- onDelete : ( time : number ) => void
38+ onDelete : ( timeWithTrackA : string ) => void
3739} ) => {
3840 const [ add , updateAdd ] = useState < AddSession > ( {
3941 name : '' ,
4042 hour : '19' ,
4143 minute : '45' ,
4244 url : '' ,
45+ track : '' ,
4346 } )
4447 const inputRef = useRef < HTMLInputElement > ( null )
4548 const isInputValid = ( ) => {
@@ -67,12 +70,13 @@ export const Editor = ({
6770 ...add ,
6871 name : '' ,
6972 url : '' ,
73+ track : '' ,
7074 } )
7175 inputRef . current ?. focus ( )
7276 }
7377
7478 return (
75- < >
79+ < form className = { formStyles . Form } >
7680 < table className = { tableStyles . Table } >
7781 < thead >
7882 < tr >
@@ -95,113 +99,143 @@ export const Editor = ({
9599 </ button >
96100 </ td >
97101 < td className = "time" >
98- < input
99- className = { formStyles . NumberInput }
100- ref = { inputRef }
101- type = "text"
102- inputMode = "numeric"
103- value = { add . hour }
104- onChange = { ( { target : { value } } ) => {
105- updateAdd ( {
106- ...add ,
107- hour : value ,
108- } )
109- } }
110- name = "session-hour"
111- />
112- { ':' }
113- < input
114- className = { formStyles . NumberInput }
115- type = "text"
116- inputMode = "numeric"
117- value = { add . minute }
118- onChange = { ( { target : { value } } ) => {
119- updateAdd ( {
120- ...add ,
121- minute : value ,
122- } )
123- } }
124- name = "session-minute"
125- />
102+ < fieldset >
103+ < legend > Local time</ legend >
104+ < input
105+ className = { formStyles . NumberInput }
106+ ref = { inputRef }
107+ type = "text"
108+ inputMode = "numeric"
109+ value = { add . hour }
110+ onChange = { ( { target : { value } } ) => {
111+ updateAdd ( {
112+ ...add ,
113+ hour : value ,
114+ } )
115+ } }
116+ name = "session-hour"
117+ maxLength = { 2 }
118+ />
119+ { ':' }
120+ < input
121+ className = { formStyles . NumberInput }
122+ type = "text"
123+ inputMode = "numeric"
124+ value = { add . minute }
125+ onChange = { ( { target : { value } } ) => {
126+ updateAdd ( {
127+ ...add ,
128+ minute : value ,
129+ } )
130+ } }
131+ name = "session-minute"
132+ maxLength = { 2 }
133+ />
134+ </ fieldset >
135+ < fieldset >
136+ < label htmlFor = "track" > Track/Room</ label >
137+ < input
138+ className = { formStyles . TextInput }
139+ type = "text"
140+ value = { add . track ?? '' }
141+ id = { 'track' }
142+ onChange = { ( { target : { value } } ) =>
143+ updateAdd ( {
144+ ...add ,
145+ track : value ,
146+ } )
147+ }
148+ placeholder = 'e.g. "Main room"'
149+ name = "session-track"
150+ />
151+ </ fieldset >
126152 </ td >
127153 < td >
128- < form className = { formStyles . Form } >
129- < fieldset >
130- < label htmlFor = "name" > Session name</ label >
131- < input
132- className = { formStyles . TextInput }
133- type = "text"
134- value = { add . name }
135- id = { 'name' }
136- onKeyUp = { ( { key } ) => {
137- if ( key === 'Enter' ) {
138- if ( isInputValid ( ) ) {
139- addAction ( add )
140- onAdd ( add )
141- }
154+ < fieldset >
155+ < label htmlFor = "name" > Session name</ label >
156+ < input
157+ className = { formStyles . TextInput }
158+ type = "text"
159+ value = { add . name }
160+ id = { 'name' }
161+ onKeyUp = { ( { key } ) => {
162+ if ( key === 'Enter' ) {
163+ if ( isInputValid ( ) ) {
164+ addAction ( add )
165+ onAdd ( add )
142166 }
143- } }
144- onChange = { ( { target : { value } } ) =>
145- updateAdd ( {
146- ...add ,
147- name : value ,
148- } )
149- }
150- placeholder = 'e.g. "Intro Session"'
151- name = "session-name"
152- />
153- </ fieldset >
154- < fieldset >
155- < label htmlFor = "url" >
156- Optional: URL to use as a hyperlink.
157- </ label >
158- < input
159- className = { formStyles . TextInput }
160- type = "url"
161- id = "url"
162- value = { add . url ?? '' }
163- onChange = { ( { target : { value } } ) =>
164- updateAdd ( {
165- ...add ,
166- url : value ,
167- } )
168167 }
169- onKeyUp = { ( { key } ) => {
170- if ( key === 'Enter' ) {
171- if ( isInputValid ( ) ) {
172- addAction ( add )
173- onAdd ( add )
174- }
168+ } }
169+ onChange = { ( { target : { value } } ) =>
170+ updateAdd ( {
171+ ...add ,
172+ name : value ,
173+ } )
174+ }
175+ placeholder = 'e.g. "Intro Session"'
176+ name = "session-name"
177+ />
178+ </ fieldset >
179+ < fieldset >
180+ < label htmlFor = "url" >
181+ Optional: URL to use as a hyperlink.
182+ </ label >
183+ < input
184+ className = { formStyles . TextInput }
185+ type = "url"
186+ id = "url"
187+ value = { add . url ?? '' }
188+ onChange = { ( { target : { value } } ) =>
189+ updateAdd ( {
190+ ...add ,
191+ url : value ,
192+ } )
193+ }
194+ onKeyUp = { ( { key } ) => {
195+ if ( key === 'Enter' ) {
196+ if ( isInputValid ( ) ) {
197+ addAction ( add )
198+ onAdd ( add )
175199 }
176- } }
177- placeholder = 'e.g. "https://example.com/"'
178- />
179- </ fieldset >
180- </ form >
200+ }
201+ } }
202+ placeholder = 'e.g. "https://example.com/"'
203+ / >
204+ </ fieldset >
181205 </ td >
182206 </ tr >
183- { Object . entries ( sessions ) . map ( ( [ time , name ] ) => (
184- < tr key = { time } >
185- < td >
186- < button
187- className = { formStyles . DeleteButton }
188- onClick = { ( ) => {
189- onDelete ( time as unknown as number )
190- } }
191- >
192- < DeleteIcon />
193- </ button >
194- </ td >
195- < td className = { 'time' } >
196- { formatEventTime ( eventTime ( time as unknown as number ) ) }
197- </ td >
198- < td >
199- < SessionName name = { name } />
200- </ td >
201- </ tr >
202- ) ) }
207+ { Object . entries ( sessions )
208+ . sort (
209+ ( [ timeWithTrackA ] , [ timeWithTrackB ] ) =>
210+ parseInt ( timeWithTrackA . split ( '@' ) [ 0 ] ) -
211+ parseInt ( timeWithTrackB . split ( '@' ) [ 0 ] ) ,
212+ )
213+ . map ( ( [ timeWithTrack , name ] ) => {
214+ const [ time , track ] = timeWithTrack . split ( '@' )
215+ return (
216+ < tr key = { timeWithTrack } >
217+ < td >
218+ < button
219+ className = { formStyles . DeleteButton }
220+ onClick = { ( ) => {
221+ onDelete ( timeWithTrack )
222+ } }
223+ >
224+ < DeleteIcon />
225+ </ button >
226+ </ td >
227+ < td className = { 'time' } >
228+ { formatEventTime ( eventTime ( parseInt ( time , 10 ) ) ) }
229+ { track === undefined ? '' : ` @ ${ track } ` }
230+ </ td >
231+ < td >
232+ < SessionName name = { name } />
233+ </ td >
234+ </ tr >
235+ )
236+ } ) }
203237 </ tbody >
204238 </ table >
205- </ >
239+ </ form >
206240 )
207241}
0 commit comments