@@ -17,6 +17,7 @@ import api from "../../services/api";
17
17
import staticData from "../../services/static-data" ;
18
18
19
19
import style from "./style.module.scss" ;
20
+ import _ from "lodash" ;
20
21
21
22
const colorIterator = makeColorIterator ( avatarColors ) ;
22
23
@@ -61,6 +62,7 @@ export default function SearchGlobal({ keyword }) {
61
62
const dropdownRef = React . useRef ( null ) ;
62
63
63
64
const prevOrderBy = usePrevious ( orderBy ) ;
65
+ const [ prevCriteria , setPrevCriteria ] = React . useState ( null ) ;
64
66
65
67
const usersPerPage = config . ITEMS_PER_PAGE ;
66
68
@@ -129,71 +131,77 @@ export default function SearchGlobal({ keyword }) {
129
131
return ;
130
132
}
131
133
134
+ const criteria = { } ;
135
+ if (
136
+ searchContext . filters [ FILTERS . LOCATIONS ] . active &&
137
+ searchContext . selectedLocations . length > 0
138
+ ) {
139
+ criteria . locations = searchContext . selectedLocations ;
140
+ }
141
+ if (
142
+ searchContext . filters [ FILTERS . SKILLS ] . active &&
143
+ searchContext . selectedSkills . length > 0
144
+ ) {
145
+ criteria . skills = searchContext . selectedSkills ;
146
+ }
147
+ if (
148
+ searchContext . filters [ FILTERS . ACHIEVEMENTS ] . active &&
149
+ searchContext . selectedAchievements . length > 0
150
+ ) {
151
+ criteria . achievements = searchContext . selectedAchievements ;
152
+ }
153
+ if ( searchContext . filters [ FILTERS . AVAILABILITY ] . active ) {
154
+ if (
155
+ searchContext . selectedAvailability &&
156
+ ( "isAvailableSelected" in searchContext . selectedAvailability ||
157
+ "isUnavailableSelected" in searchContext . selectedAvailability )
158
+ ) {
159
+ const availabilityFilter = searchContext . selectedAvailability ;
160
+ if (
161
+ availabilityFilter . isAvailableSelected &&
162
+ ! availabilityFilter . isUnavailableSelected
163
+ ) {
164
+ criteria . isAvailable = true ;
165
+ } else if (
166
+ ! availabilityFilter . isAvailableSelected &&
167
+ availabilityFilter . isUnavailableSelected
168
+ ) {
169
+ criteria . isAvailable = false ;
170
+ }
171
+ }
172
+ }
173
+
174
+ criteria . attributes = [ ] ;
175
+ searchContext . getCompanyAttrActiveFilter ( ) . forEach ( ( filter ) => {
176
+ if (
177
+ searchContext . selectedCompanyAttributes [ filter . id ] &&
178
+ searchContext . selectedCompanyAttributes [ filter . id ] . length > 0
179
+ ) {
180
+ criteria . attributes . push ( {
181
+ id : filter . id ,
182
+ value : searchContext . selectedCompanyAttributes [ filter . id ] . map (
183
+ ( data ) => data . value
184
+ ) ,
185
+ } ) ;
186
+ }
187
+ } ) ;
188
+
189
+ if ( _ . isEqual ( prevCriteria , criteria ) ) {
190
+ return ;
191
+ } else {
192
+ setPrevCriteria ( criteria ) ;
193
+ }
194
+
132
195
let isSubscribed = true ;
133
196
let source = axios . CancelToken . source ( ) ;
134
197
135
198
( async ( ) => {
136
- const criteria = { } ;
137
199
let headers ;
138
200
let data ;
139
201
140
202
setIsSearching ( true ) ;
141
203
setUsers ( [ ] ) ;
142
204
143
- if (
144
- searchContext . filters [ FILTERS . LOCATIONS ] . active &&
145
- searchContext . selectedLocations . length > 0
146
- ) {
147
- criteria . locations = searchContext . selectedLocations ;
148
- }
149
- if (
150
- searchContext . filters [ FILTERS . SKILLS ] . active &&
151
- searchContext . selectedSkills . length > 0
152
- ) {
153
- criteria . skills = searchContext . selectedSkills ;
154
- }
155
- if (
156
- searchContext . filters [ FILTERS . ACHIEVEMENTS ] . active &&
157
- searchContext . selectedAchievements . length > 0
158
- ) {
159
- criteria . achievements = searchContext . selectedAchievements ;
160
- }
161
- if ( searchContext . filters [ FILTERS . AVAILABILITY ] . active ) {
162
- if (
163
- searchContext . selectedAvailability &&
164
- ( "isAvailableSelected" in searchContext . selectedAvailability ||
165
- "isUnavailableSelected" in searchContext . selectedAvailability )
166
- ) {
167
- const availabilityFilter = searchContext . selectedAvailability ;
168
- if (
169
- availabilityFilter . isAvailableSelected &&
170
- ! availabilityFilter . isUnavailableSelected
171
- ) {
172
- criteria . isAvailable = true ;
173
- } else if (
174
- ! availabilityFilter . isAvailableSelected &&
175
- availabilityFilter . isUnavailableSelected
176
- ) {
177
- criteria . isAvailable = false ;
178
- }
179
- }
180
- }
181
-
182
- criteria . attributes = [ ] ;
183
- searchContext . getCompanyAttrActiveFilter ( ) . forEach ( ( filter ) => {
184
- if (
185
- searchContext . selectedCompanyAttributes [ filter . id ] &&
186
- searchContext . selectedCompanyAttributes [ filter . id ] . length > 0
187
- ) {
188
- criteria . attributes . push ( {
189
- id : filter . id ,
190
- value : searchContext . selectedCompanyAttributes [ filter . id ] . map (
191
- ( data ) => data . value
192
- ) ,
193
- } ) ;
194
- }
195
- } ) ;
196
-
197
205
// reset first page when change orderBy
198
206
if ( prevOrderBy !== "undefined" && prevOrderBy !== orderBy ) {
199
207
searchContext . pagination . page = 1 ;
@@ -245,11 +253,6 @@ export default function SearchGlobal({ keyword }) {
245
253
setTotalPages ( Number ( headers [ "x-total-pages" ] ) ) ;
246
254
}
247
255
} ) ( ) ;
248
-
249
- return ( ) => {
250
- isSubscribed = false ;
251
- source . cancel ( "Cancelling in cleanup" ) ;
252
- } ;
253
256
// eslint-disable-next-line react-hooks/exhaustive-deps
254
257
} , [ isLoading , isAuthenticated , keyword , orderBy , searchContext ] ) ;
255
258
0 commit comments