@@ -56,6 +56,7 @@ export class SearchBarInner extends Component {
56
56
this . getSuggestionList = this . getSuggestionList . bind ( this ) ;
57
57
this . handleSearchChange = this . handleSearchChange . bind ( this ) ;
58
58
this . handleClickOutside = this . handleClickOutside . bind ( this ) ;
59
+ this . onKeyDown = this . onKeyDown . bind ( this ) ;
59
60
// using debounce to avoid processing or requesting too much
60
61
this . updateSuggestionListWithNewSearch = _ . debounce (
61
62
this . updateSuggestionListWithNewSearch . bind ( this ) , 400 ,
@@ -71,6 +72,29 @@ export class SearchBarInner extends Component {
71
72
document . removeEventListener ( 'mousedown' , this . handleClickOutside ) ;
72
73
}
73
74
75
+ onKeyDown ( e ) {
76
+ const { inputlVal, selectedFilter } = this . state ;
77
+ if ( inputlVal && e . which === 13 ) {
78
+ const searchQuery = { } ;
79
+ if ( this . searchFieldRef && this . searchFieldRef . value ) {
80
+ if ( selectedFilter . name === 'Tags' ) {
81
+ searchQuery . tags = [ this . searchFieldRef . value ] ;
82
+ }
83
+ if ( selectedFilter . name === 'All' ) {
84
+ searchQuery . phrase = this . searchFieldRef . value ;
85
+ }
86
+ if ( selectedFilter . name === 'Title' ) {
87
+ searchQuery . title = this . searchFieldRef . value ;
88
+ }
89
+ }
90
+ if ( selectedFilter . name !== 'Author' ) {
91
+ window . location . href = `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_SEARCH_PATH } ?${ qs . stringify ( searchQuery ) } ` ;
92
+ } else {
93
+ window . location . href = `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_SEARCH_PATH } ?author=${ inputlVal } ` ;
94
+ }
95
+ }
96
+ }
97
+
74
98
/**
75
99
* Set the search field ref
76
100
*/
@@ -136,6 +160,7 @@ export class SearchBarInner extends Component {
136
160
isShowSuggestion,
137
161
suggestionList,
138
162
selectedFilter,
163
+ noResults,
139
164
} = this . state ;
140
165
141
166
const searchQuery = { } ;
@@ -151,7 +176,8 @@ export class SearchBarInner extends Component {
151
176
}
152
177
}
153
178
154
- return ( suggestionList && ! _ . isEmpty ( suggestionList ) && isShowSuggestion && (
179
+ // eslint-disable-next-line no-nested-ternary
180
+ return suggestionList && ! _ . isEmpty ( suggestionList ) && isShowSuggestion ? (
155
181
< div
156
182
className = { theme [ 'popup-search-result' ] }
157
183
ref = { this . setPopupSearchResultRef }
@@ -319,7 +345,14 @@ export class SearchBarInner extends Component {
319
345
) : null
320
346
}
321
347
</ div >
322
- ) ) ;
348
+ ) : noResults ? (
349
+ < div
350
+ className = { theme [ 'popup-search-result' ] }
351
+ ref = { this . setPopupSearchResultRef }
352
+ >
353
+ < span > No Results</ span >
354
+ </ div >
355
+ ) : null ;
323
356
}
324
357
325
358
handleClickOutside ( e ) {
@@ -379,23 +412,26 @@ export class SearchBarInner extends Component {
379
412
. then ( ( results ) => {
380
413
// Nothing found?
381
414
if ( ! results . total ) {
382
- this . setState ( { suggestionList : { } } ) ;
415
+ this . setState ( {
416
+ suggestionList : { } ,
417
+ noResults : true ,
418
+ } ) ;
383
419
return ;
384
420
}
385
421
// Author query?
386
422
if ( selectedFilter . name === 'Author' ) {
387
423
const suggestionList = {
388
424
Author : _ . map ( results . items , item => ( { ...item . fields } ) ) ,
389
425
} ;
390
- this . setState ( { suggestionList } ) ;
426
+ this . setState ( { suggestionList, noResults : false } ) ;
391
427
return ;
392
428
}
393
429
// ALL && Tags
394
430
const suggestionList = this . groupResults ( results ) ;
395
431
this . setState ( { suggestionList } ) ;
396
432
} ) ;
397
433
} else {
398
- this . setState ( { suggestionList : { } } ) ;
434
+ this . setState ( { suggestionList : { } , noResults : false } ) ;
399
435
}
400
436
}
401
437
@@ -419,6 +455,7 @@ export class SearchBarInner extends Component {
419
455
contentAuthor : contentAuthor . fields ,
420
456
externalArticle : fields . externalArticle ,
421
457
contentUrl : fields . contentUrl ,
458
+ slug : fields . slug ,
422
459
} ;
423
460
} ) ,
424
461
'type' ,
@@ -471,6 +508,7 @@ export class SearchBarInner extends Component {
471
508
document . addEventListener ( 'mousedown' , this . handleClickOutside ) ;
472
509
} }
473
510
onChange = { this . handleSearchChange }
511
+ onKeyDown = { this . onKeyDown }
474
512
/>
475
513
< div className = { theme . dropdown } >
476
514
< button
0 commit comments