@@ -55,7 +55,8 @@ type Props = ReactProps & ReduxStateProps & ReduxDispatchProps & DefaultProps
5555
5656type State = {
5757 filters : Array < FilterType > ,
58- query : string ,
58+ typedQuery : string ,
59+ searchQuery : string ,
5960 mode : 'loading' | 'browsing' | 'searching' | 'ready' ,
6061}
6162
@@ -73,7 +74,8 @@ class CourseSearchView extends React.Component<Props, State> {
7374 state = {
7475 mode : 'loading' ,
7576 filters : [ ] ,
76- query : '' ,
77+ typedQuery : '' ,
78+ searchQuery : '' ,
7779 }
7880
7981 componentDidMount ( ) {
@@ -106,29 +108,38 @@ class CourseSearchView extends React.Component<Props, State> {
106108 }
107109
108110 handleSearchSubmit = ( ) = > {
109- this . setState ( ( ) => ( { mode : 'searching' } ) )
110-
111- let { query } = this . state
112- if ( query . length !== 0 ) {
113- this . props . updateRecentSearches ( query )
114- }
111+ this . setState (
112+ state => {
113+ return { mode : 'searching' , searchQuery : state . typedQuery }
114+ } ,
115+ ( ) => {
116+ let { searchQuery : query } = this . state
117+ if ( query . length !== 0 ) {
118+ this . props . updateRecentSearches ( query )
119+ }
120+ } ,
121+ )
115122 }
116123
117124 handleSearchCancel = ( ) = > {
118- this . setState ( ( ) => ( { query : '' , mode : 'ready' } ) )
125+ this . setState ( ( ) => ( { typedQuery : '' , searchQuery : '' , mode : 'ready' } ) )
119126 this . resetFilters ( )
120127 }
121128
122129 handleSearchChange = ( value : string ) = > {
123- this . setState ( ( ) => ( { query : value } ) )
130+ this . setState ( ( ) => ( { typedQuery : value } ) )
124131 }
125132
126133 handleSearchFocus = ( ) = > {
127134 this . setState ( ( ) => ( { mode : 'searching' } ) )
128135 }
129136
130137 onRecentSearchPress = ( text : string ) = > {
131- this . setState ( ( ) => ( { query : text , mode : 'searching' } ) )
138+ this . setState ( ( ) => ( {
139+ typedQuery : text ,
140+ searchQuery : text ,
141+ mode : 'searching' ,
142+ } ) )
132143 }
133144
134145 onRecentFilterPress = async ( text : string ) = > {
@@ -168,7 +179,7 @@ class CourseSearchView extends React.Component<Props, State> {
168179 }
169180
170181 render ( ) {
171- let { query , mode, filters} = this . state
182+ let { typedQuery , searchQuery , mode, filters} = this . state
172183
173184 if ( mode === 'loading' ) {
174185 return < LoadingView text = "Loading Course Data…" />
@@ -207,7 +218,7 @@ class CourseSearchView extends React.Component<Props, State> {
207218 onSubmit = { this . handleSearchSubmit }
208219 placeholder = { placeholderPrompt }
209220 title = "Search Courses"
210- value = { query }
221+ value = { typedQuery }
211222 />
212223
213224 < Separator />
@@ -220,7 +231,7 @@ class CourseSearchView extends React.Component<Props, State> {
220231 filters = { filters }
221232 navigation = { this . props . navigation }
222233 openFilterView = { this . openFilterView }
223- query = { query }
234+ query = { searchQuery }
224235 updateRecentFilters = { this . props . updateRecentFilters }
225236 />
226237 ) : (
0 commit comments