@@ -111,7 +111,7 @@ class Navigation extends Component {
111
111
var idKey = ontologyToID [ this . state . displayOntology ] ;
112
112
if ( this . state . timeFilterOn ) {
113
113
// filter by time to get array with display artifacts that fit the time filter
114
- var itemsWithinFieldtrips = dateFilterHelper ( this . refs . fromDate . value , this . refs . toDate . value , this . state . displayOntology ) ;
114
+ let itemsWithinFieldtrips = dateFilterHelper ( this . state . fromDate , this . state . toDate , this . state . displayOntology ) ;
115
115
// if an item is in the itemsWithinFieldtrips, change what is displayed, NOT items list
116
116
var displayList = [ ] ;
117
117
// if it isn't a fieldtrip
@@ -155,65 +155,50 @@ class Navigation extends Component {
155
155
}
156
156
157
157
// sets time filters
158
- timeFilterHandler ( ) {
159
- let fromDateForm = parseInt ( this . refs . fromDate . value , 10 ) ;
160
- let toDateForm = parseInt ( this . refs . toDate . value , 10 ) ;
161
- // check if the dates are valid dates (4 digits, between 1887 and 1899)
162
- if ( fromDateForm >= 1887 && toDateForm <= 1899 ) {
163
- // check if time filter was switched
164
- if ( this . refs . TimeFilterOn . checked !== this . state . timeFilterOn ) {
165
- // if they are, then set this.state variables
158
+ timeFilterHandler ( filter , event ) {
159
+ switch ( filter ) {
160
+ case "fromDate" :
166
161
this . setState ( {
167
- "timeFilterOn" : ! this . state . timeFilterOn ,
168
- "fromDate" : fromDateForm ,
169
- "toDate" : toDateForm ,
170
- } , ( ) => {
171
- this . updateItems . bind ( this ) ( ) ;
162
+ "fromDate" : event . target . value ,
163
+ } , function ( ) {
164
+ // check if the dates are valid dates (4 digits, between 1887 and 1899)
165
+ if ( this . state . fromDate >= 1887 ) {
166
+ this . updateItems ( ) ;
167
+ }
172
168
} ) ;
173
- } else {
174
- // just change from/to dates
169
+ break ;
170
+ case "toDate" :
175
171
this . setState ( {
176
- "fromDate" : fromDateForm ,
177
- "toDate" : toDateForm ,
178
- } , ( ) => {
179
- this . updateItems . bind ( this ) ( ) ;
172
+ "toDate" : event . target . value ,
173
+ } , function ( ) {
174
+ // check if the dates are valid dates (4 digits, between 1887 and 1899)
175
+ if ( this . state . toDate <= 1899 ) {
176
+ this . updateItems ( ) ;
177
+ }
180
178
} ) ;
181
- }
179
+ break ;
180
+ case "timelineFilter" :
181
+ this . setState ( {
182
+ "timeFilterOn" : event . target . checked ,
183
+ } , function ( ) {
184
+ this . updateItems ( ) ;
185
+ } ) ;
186
+ break ;
187
+ default :
188
+ console . warn ( `Invalid filter: ${ filter } ` ) ;
182
189
}
183
190
}
184
191
185
192
timeInputClickHandler ( year ) {
186
- // display slider
187
- if ( year === "ToYear" ) {
188
- // set this.state.toSelect = true
189
- this . setState ( ( ) => {
190
- return { "toSelect" : true } ;
191
- } ) ;
192
- } else {
193
- // set this.state.fromSelect = true
194
- this . setState ( ( ) => {
195
- return { "fromSelect" : true } ;
196
- } ) ;
197
- }
193
+ this . setState ( {
194
+ [ year === "ToYear" ? "toSelect" : "fromSelect" ] : true ,
195
+ } ) ;
198
196
}
199
197
200
198
timeInputEnd ( year ) {
201
- // display slider
202
- if ( year === "toDate" ) {
203
- // set this.state.toSelect = true
204
- this . setState ( ( ) => {
205
- return { "toSelect" : false } ;
206
- } , ( ) => {
207
- this . timeFilterHandler . bind ( this ) ;
208
- } ) ;
209
- } else {
210
- // set this.state.fromSelect = true
211
- this . setState ( ( ) => {
212
- return { "fromSelect" : false } ;
213
- } , ( ) => {
214
- this . timeFilterHandler . bind ( this ) ;
215
- } ) ;
216
- }
199
+ this . setState ( {
200
+ [ year === "toDate" ? "toSelect" : "fromSelect" ] : false ,
201
+ } ) ;
217
202
}
218
203
219
204
flipSearch ( CurrentState ) {
@@ -285,7 +270,7 @@ class Navigation extends Component {
285
270
< div className = "medium-2 medium-offset-1 cell" >
286
271
< div className = "switch" >
287
272
< input className = "switch-input" id = "exampleSwitch" type = "checkbox" checked = { this . state . timeFilterOn }
288
- name = "exampleSwitch" onChange = { this . timeFilterHandler . bind ( this ) } ref = "TimeFilterOn" />
273
+ name = "exampleSwitch" onChange = { this . timeFilterHandler . bind ( this , "timelineFilter" ) } />
289
274
< label className = "switch-paddle" htmlFor = "exampleSwitch" > < br />
290
275
< span style = { { "fontSize" : ".8em" , "color" : "black" , "width" : "150%" } } > Timeline</ span >
291
276
< span className = "show-for-sr" > Enable Timeline</ span >
@@ -294,38 +279,56 @@ class Navigation extends Component {
294
279
</ div >
295
280
< div className = "medium-2 cell text" > < b > From</ b > </ div >
296
281
< div className = "medium-2 cell" >
297
- < input className = "year" type = "text" name = "FromYear" ref = "fromDate"
282
+ < input
283
+ className = "year"
284
+ type = "number"
285
+ name = "FromYear"
286
+ min = { 1887 }
287
+ max = { this . state . toDate }
298
288
value = { this . state . fromDate }
299
- onChange = { this . timeFilterHandler . bind ( this ) } onClick = { ( e ) => {
289
+ onChange = { this . timeFilterHandler . bind ( this , "fromDate" ) }
290
+ onClick = { ( e ) => {
300
291
e . preventDefault ( ) ;
301
292
this . timeInputClickHandler . bind ( this ) ( "FromYear" ) ;
302
293
} } />
303
- < input className = { `slider ${ this . state . fromSelect ? "active" : "" } ` }
304
- type = "range" min = "1887" max = { this . state . toDate } value = { this . state . fromDate }
305
- onChange = { this . timeFilterHandler . bind ( this ) }
294
+ < input
295
+ className = { `slider ${ this . state . fromSelect ? "active" : "" } ` }
296
+ type = "range"
297
+ min = "1887"
298
+ max = { this . state . toDate }
299
+ value = { this . state . fromDate }
300
+ onChange = { this . timeFilterHandler . bind ( this , "fromDate" ) }
306
301
onMouseUp = { ( e ) => {
307
302
e . preventDefault ( ) ;
308
303
this . timeInputEnd . bind ( this ) ( "fromDate" ) ;
309
304
} }
310
- ref = "fromDate"
311
305
id = "myRange" />
312
306
</ div >
313
307
< div className = "medium-1 cell text" > < b > To</ b > </ div >
314
308
< div className = "medium-2 cell" >
315
- < input className = "year" type = "text" name = "ToYear" ref = "toDate"
309
+ < input
310
+ className = "year"
311
+ type = "number"
312
+ name = "ToYear"
313
+ min = { this . state . fromDate }
314
+ max = { 1899 }
316
315
value = { this . state . toDate }
317
- onChange = { this . timeFilterHandler . bind ( this ) } onClick = { ( e ) => {
316
+ onChange = { this . timeFilterHandler . bind ( this , "toDate" ) }
317
+ onClick = { ( e ) => {
318
318
e . preventDefault ( ) ;
319
319
this . timeInputClickHandler . bind ( this ) ( "ToYear" ) ;
320
320
} } />
321
- < input className = { `slider ${ this . state . toSelect ? "active" : "" } ` }
322
- type = "range" min = { this . state . fromDate } max = "1899" value = { this . state . toDate }
323
- onChange = { this . timeFilterHandler . bind ( this ) }
321
+ < input
322
+ className = { `slider ${ this . state . toSelect ? "active" : "" } ` }
323
+ type = "range"
324
+ min = { this . state . fromDate }
325
+ max = "1899"
326
+ value = { this . state . toDate }
327
+ onChange = { this . timeFilterHandler . bind ( this , "toDate" ) }
324
328
onMouseUp = { ( e ) => {
325
329
e . preventDefault ( ) ;
326
330
this . timeInputEnd . bind ( this ) ( "toDate" ) ;
327
331
} }
328
- ref = "toDate"
329
332
id = "myRange" />
330
333
</ div >
331
334
</ form >
0 commit comments