Merge branch 'search-race-condition' into 'develop'
Fix another race condition in search results See merge request soapbox-pub/soapbox-fe!929
This commit is contained in:
commit
955687d719
|
@ -39,6 +39,7 @@ export function clearSearch() {
|
||||||
export function submitSearch(filter) {
|
export function submitSearch(filter) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const value = getState().getIn(['search', 'value']);
|
const value = getState().getIn(['search', 'value']);
|
||||||
|
const type = filter || getState().getIn(['search', 'filter'], 'accounts');
|
||||||
|
|
||||||
// An empty search doesn't return any results
|
// An empty search doesn't return any results
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
|
@ -52,7 +53,7 @@ export function submitSearch(filter) {
|
||||||
q: value,
|
q: value,
|
||||||
resolve: true,
|
resolve: true,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
type: filter || getState().getIn(['search', 'filter'], 'accounts'),
|
type,
|
||||||
},
|
},
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.data.accounts) {
|
if (response.data.accounts) {
|
||||||
|
@ -63,7 +64,7 @@ export function submitSearch(filter) {
|
||||||
dispatch(importFetchedStatuses(response.data.statuses));
|
dispatch(importFetchedStatuses(response.data.statuses));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(fetchSearchSuccess(response.data, value));
|
dispatch(fetchSearchSuccess(response.data, value, type));
|
||||||
dispatch(fetchRelationships(response.data.accounts.map(item => item.id)));
|
dispatch(fetchRelationships(response.data.accounts.map(item => item.id)));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(fetchSearchFail(error));
|
dispatch(fetchSearchFail(error));
|
||||||
|
@ -78,11 +79,12 @@ export function fetchSearchRequest(value) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchSearchSuccess(results, searchTerm) {
|
export function fetchSearchSuccess(results, searchTerm, searchType) {
|
||||||
return {
|
return {
|
||||||
type: SEARCH_FETCH_SUCCESS,
|
type: SEARCH_FETCH_SUCCESS,
|
||||||
results,
|
results,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
|
searchType,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ const toIds = items => {
|
||||||
return ImmutableOrderedSet(items.map(item => item.id));
|
return ImmutableOrderedSet(items.map(item => item.id));
|
||||||
};
|
};
|
||||||
|
|
||||||
const importResults = (state, results, searchTerm) => {
|
const importResults = (state, results, searchTerm, searchType) => {
|
||||||
return state.withMutations(state => {
|
return state.withMutations(state => {
|
||||||
if (state.get('value') === searchTerm) {
|
if (state.get('value') === searchTerm && state.get('filter') === searchType) {
|
||||||
state.set('results', ImmutableMap({
|
state.set('results', ImmutableMap({
|
||||||
accounts: toIds(results.accounts),
|
accounts: toIds(results.accounts),
|
||||||
statuses: toIds(results.statuses),
|
statuses: toIds(results.statuses),
|
||||||
|
@ -81,7 +81,7 @@ export default function search(state = initialState, action) {
|
||||||
case SEARCH_FETCH_REQUEST:
|
case SEARCH_FETCH_REQUEST:
|
||||||
return handleSubmitted(state, action.value);
|
return handleSubmitted(state, action.value);
|
||||||
case SEARCH_FETCH_SUCCESS:
|
case SEARCH_FETCH_SUCCESS:
|
||||||
return importResults(state, action.results, action.searchTerm);
|
return importResults(state, action.results, action.searchTerm, action.searchType);
|
||||||
case SEARCH_FILTER_SET:
|
case SEARCH_FILTER_SET:
|
||||||
return state.set('filter', action.value);
|
return state.set('filter', action.value);
|
||||||
case SEARCH_EXPAND_REQUEST:
|
case SEARCH_EXPAND_REQUEST:
|
||||||
|
|
Loading…
Reference in New Issue