diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index d14d13152..6764dc534 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -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, }; } diff --git a/app/soapbox/reducers/search.js b/app/soapbox/reducers/search.js index b950e5f58..80a4bc9c8 100644 --- a/app/soapbox/reducers/search.js +++ b/app/soapbox/reducers/search.js @@ -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: