From e46e217d572ebb3ed0b015c70ee472ee11609355 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Nov 2021 15:20:17 -0600 Subject: [PATCH 1/4] Search: don't infer filter from results, leave it alone --- app/soapbox/reducers/search.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/app/soapbox/reducers/search.js b/app/soapbox/reducers/search.js index 47aa9f00b..8a4ec4c5b 100644 --- a/app/soapbox/reducers/search.js +++ b/app/soapbox/reducers/search.js @@ -28,21 +28,7 @@ const toIds = items => { return ImmutableOrderedSet(items.map(item => item.id)); }; -const getResultsFilter = results => { - if (results.accounts.length > 0) { - return 'accounts'; - } else if (results.statuses.length > 0) { - return 'statuses'; - } else if (results.hashtags.length > 0) { - return 'hashtags'; - } else { - return 'accounts'; - } -}; - const importResults = (state, results) => { - const filter = getResultsFilter(results); - return state.withMutations(state => { state.set('results', ImmutableMap({ accounts: toIds(results.accounts), @@ -57,7 +43,6 @@ const importResults = (state, results) => { })); state.set('submitted', true); - state.set('filter', filter); }); }; From 2c1e6d12f92d8853cd89984ffcb026da1da600df Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Nov 2021 15:31:32 -0600 Subject: [PATCH 2/4] Search: clear search when backspaced all the way --- app/soapbox/actions/search.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index 6f1621ad4..d23457ba5 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -17,9 +17,16 @@ export const SEARCH_EXPAND_SUCCESS = 'SEARCH_EXPAND_SUCCESS'; export const SEARCH_EXPAND_FAIL = 'SEARCH_EXPAND_FAIL'; export function changeSearch(value) { - return { - type: SEARCH_CHANGE, - value, + return (dispatch, getState) => { + // If backspaced all the way, clear the search + if (value.length === 0) { + return dispatch(clearSearch()); + } else { + return dispatch({ + type: SEARCH_CHANGE, + value, + }); + } }; } @@ -33,6 +40,7 @@ export function submitSearch() { return (dispatch, getState) => { const value = getState().getIn(['search', 'value']); + // An empty search doesn't return any results if (value.length === 0) { return; } From ad70e391436b1682b60cfb8088e5b00fc43395f1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Nov 2021 15:59:08 -0600 Subject: [PATCH 3/4] Search: only search for results in the current filter --- app/soapbox/actions/search.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index d23457ba5..76d39416a 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -39,6 +39,7 @@ export function clearSearch() { export function submitSearch() { return (dispatch, getState) => { const value = getState().getIn(['search', 'value']); + const filter = getState().getIn(['search', 'filter'], 'accounts'); // An empty search doesn't return any results if (value.length === 0) { @@ -52,6 +53,7 @@ export function submitSearch() { q: value, resolve: true, limit: 20, + type: filter, }, }).then(response => { if (response.data.accounts) { From e54253d155bc4bc0579436aaa6c8155752200d71 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Nov 2021 16:03:20 -0600 Subject: [PATCH 4/4] Search: resubmit when changing tabs --- app/soapbox/actions/search.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index 76d39416a..ca515d06c 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -36,10 +36,9 @@ export function clearSearch() { }; } -export function submitSearch() { +export function submitSearch(filter) { return (dispatch, getState) => { const value = getState().getIn(['search', 'value']); - const filter = getState().getIn(['search', 'filter'], 'accounts'); // An empty search doesn't return any results if (value.length === 0) { @@ -53,7 +52,7 @@ export function submitSearch() { q: value, resolve: true, limit: 20, - type: filter, + type: filter || getState().getIn(['search', 'filter'], 'accounts'), }, }).then(response => { if (response.data.accounts) { @@ -93,13 +92,17 @@ export function fetchSearchFail(error) { }; } -export const setFilter = filterType => dispatch => { - dispatch({ - type: SEARCH_FILTER_SET, - path: ['search', 'filter'], - value: filterType, - }); -}; +export function setFilter(filterType) { + return (dispatch) => { + dispatch(submitSearch(filterType)); + + dispatch({ + type: SEARCH_FILTER_SET, + path: ['search', 'filter'], + value: filterType, + }); + }; +} export const expandSearch = type => (dispatch, getState) => { const value = getState().getIn(['search', 'value']);