Merge branch 'search-race-condition' into 'develop'
Fix: Race condition in search See merge request soapbox-pub/soapbox-fe!908
This commit is contained in:
commit
b706024e31
2 changed files with 26 additions and 21 deletions
|
@ -63,7 +63,7 @@ export function submitSearch(filter) {
|
|||
dispatch(importFetchedStatuses(response.data.statuses));
|
||||
}
|
||||
|
||||
dispatch(fetchSearchSuccess(response.data));
|
||||
dispatch(fetchSearchSuccess(response.data, value));
|
||||
dispatch(fetchRelationships(response.data.accounts.map(item => item.id)));
|
||||
}).catch(error => {
|
||||
dispatch(fetchSearchFail(error));
|
||||
|
@ -78,10 +78,11 @@ export function fetchSearchRequest(value) {
|
|||
};
|
||||
}
|
||||
|
||||
export function fetchSearchSuccess(results) {
|
||||
export function fetchSearchSuccess(results, searchTerm) {
|
||||
return {
|
||||
type: SEARCH_FETCH_SUCCESS,
|
||||
results,
|
||||
searchTerm,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,9 @@ const toIds = items => {
|
|||
return ImmutableOrderedSet(items.map(item => item.id));
|
||||
};
|
||||
|
||||
const importResults = (state, results) => {
|
||||
const importResults = (state, results, searchTerm) => {
|
||||
return state.withMutations(state => {
|
||||
if (state.get('value') === searchTerm) {
|
||||
state.set('results', ImmutableMap({
|
||||
accounts: toIds(results.accounts),
|
||||
statuses: toIds(results.statuses),
|
||||
|
@ -43,14 +44,17 @@ const importResults = (state, results) => {
|
|||
}));
|
||||
|
||||
state.set('submitted', true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const paginateResults = (state, searchType, results) => {
|
||||
const paginateResults = (state, searchType, results, searchTerm) => {
|
||||
return state.withMutations(state => {
|
||||
if (state.get('value') === searchTerm) {
|
||||
state.setIn(['results', `${searchType}HasMore`], results[searchType].length >= 20);
|
||||
state.setIn(['results', `${searchType}Loaded`], true);
|
||||
state.updateIn(['results', searchType], items => items.concat(results[searchType].map(item => item.id)));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -77,13 +81,13 @@ export default function search(state = initialState, action) {
|
|||
case SEARCH_FETCH_REQUEST:
|
||||
return handleSubmitted(state, action.value);
|
||||
case SEARCH_FETCH_SUCCESS:
|
||||
return importResults(state, action.results);
|
||||
return importResults(state, action.results, action.searchTerm);
|
||||
case SEARCH_FILTER_SET:
|
||||
return state.set('filter', action.value);
|
||||
case SEARCH_EXPAND_REQUEST:
|
||||
return state.setIn(['results', `${action.searchType}Loaded`], false);
|
||||
case SEARCH_EXPAND_SUCCESS:
|
||||
return paginateResults(state, action.searchType, action.results);
|
||||
return paginateResults(state, action.searchType, action.results, action.searchTerm);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue