kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Fix another race condition in search results
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>merge-requests/929/head
rodzic
d66b2e10f2
commit
b79e760b65
|
@ -39,6 +39,7 @@ export function clearSearch() {
|
|||
export function submitSearch(filter) {
|
||||
return (dispatch, getState) => {
|
||||
const value = getState().getIn(['search', 'value']);
|
||||
const type = filter || getState().getIn(['search', 'filter'], 'accounts');
|
||||
|
||||
// An empty search doesn't return any results
|
||||
if (value.length === 0) {
|
||||
|
@ -52,7 +53,7 @@ export function submitSearch(filter) {
|
|||
q: value,
|
||||
resolve: true,
|
||||
limit: 20,
|
||||
type: filter || getState().getIn(['search', 'filter'], 'accounts'),
|
||||
type,
|
||||
},
|
||||
}).then(response => {
|
||||
if (response.data.accounts) {
|
||||
|
@ -63,7 +64,7 @@ export function submitSearch(filter) {
|
|||
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)));
|
||||
}).catch(error => {
|
||||
dispatch(fetchSearchFail(error));
|
||||
|
@ -78,11 +79,12 @@ export function fetchSearchRequest(value) {
|
|||
};
|
||||
}
|
||||
|
||||
export function fetchSearchSuccess(results, searchTerm) {
|
||||
export function fetchSearchSuccess(results, searchTerm, searchType) {
|
||||
return {
|
||||
type: SEARCH_FETCH_SUCCESS,
|
||||
results,
|
||||
searchTerm,
|
||||
searchType,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ const toIds = items => {
|
|||
return ImmutableOrderedSet(items.map(item => item.id));
|
||||
};
|
||||
|
||||
const importResults = (state, results, searchTerm) => {
|
||||
const importResults = (state, results, searchTerm, searchType) => {
|
||||
return state.withMutations(state => {
|
||||
if (state.get('value') === searchTerm) {
|
||||
if (state.get('value') === searchTerm && state.get('filter') === searchType) {
|
||||
state.set('results', ImmutableMap({
|
||||
accounts: toIds(results.accounts),
|
||||
statuses: toIds(results.statuses),
|
||||
|
@ -81,7 +81,7 @@ 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, action.searchTerm);
|
||||
return importResults(state, action.results, action.searchTerm, action.searchType);
|
||||
case SEARCH_FILTER_SET:
|
||||
return state.set('filter', action.value);
|
||||
case SEARCH_EXPAND_REQUEST:
|
||||
|
|
Ładowanie…
Reference in New Issue