@@ -96,13 +96,14 @@ const triggerSearchOnMapIdle = () => {
9696 }
9797
9898 MapSearchService . searchLocations ( ) . then ( ( _data ) => {
99- handleMapSearchResponse ( _data ) ;
100- clearMapViewList ( ) ;
101- renderListingLocations ( state . listLocations ) ;
99+ handleMapSearchResponse ( _data ) . then ( ( ) => {
100+ clearMapViewList ( ) ;
101+ renderListingLocations ( state . listLocations ) ;
102+ } ) ;
102103 } ) ;
103104} ;
104105
105- const handleMapSearchResponse = ( data ) => {
106+ const handleMapSearchResponse = ( data ) => new Promise ( ( resolve , reject ) => {
106107 if ( ! data . aggregateLocations || ! data . aggregateLocations . length ) {
107108 if ( ! state . listLocations . length ) {
108109 // if there's no result and no cached data then call "renderListingLocations" to show the empty state
@@ -143,7 +144,7 @@ const handleMapSearchResponse = (data) => {
143144 if ( searchableTitles && searchableTitles . length > 0 ) {
144145 state . searchableTitles = searchableTitles ;
145146 return MapSearchService . searchLocations ( ) . then ( ( _data ) => {
146- handleMapSearchResponse ( _data ) ;
147+ resolve ( handleMapSearchResponse ( _data ) ) ;
147148 } ) ;
148149 }
149150 }
@@ -155,11 +156,11 @@ const handleMapSearchResponse = (data) => {
155156
156157 if ( ! state . fetchingEndReached && state . listLocations . length < 200 ) {
157158 return MapSearchService . searchLocations ( ) . then ( ( _data ) => {
158- handleMapSearchResponse ( _data ) ;
159+ resolve ( handleMapSearchResponse ( _data ) ) ;
159160 } ) ;
160161 }
161162
162- return result ;
163- } ;
163+ return resolve ( state . listLocations ) ;
164+ } ) ;
164165
165166export default { renderListingLocations, clearMapViewList, handleMapSearchResponse } ;
0 commit comments