From 2c1e6d12f92d8853cd89984ffcb026da1da600df Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 15 Nov 2021 15:31:32 -0600 Subject: [PATCH] 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; }