diff --git a/app/soapbox/actions/search.ts b/app/soapbox/actions/search.ts index 0268ef8fd..e8718d479 100644 --- a/app/soapbox/actions/search.ts +++ b/app/soapbox/actions/search.ts @@ -158,7 +158,7 @@ const showSearch = () => ({ type: SEARCH_SHOW, }); -const setSearchAccount = (accountId: string) => ({ +const setSearchAccount = (accountId: string | null) => ({ type: SEARCH_ACCOUNT_SET, accountId, }); diff --git a/app/soapbox/features/compose/components/search.tsx b/app/soapbox/features/compose/components/search.tsx index ad51369b4..b9eea88d4 100644 --- a/app/soapbox/features/compose/components/search.tsx +++ b/app/soapbox/features/compose/components/search.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames'; import { Map as ImmutableMap } from 'immutable'; import debounce from 'lodash/debounce'; -import * as React from 'react'; +import React, { useCallback } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useDispatch } from 'react-redux'; import { useHistory } from 'react-router-dom'; @@ -9,8 +9,9 @@ import { useHistory } from 'react-router-dom'; import { changeSearch, clearSearch, - submitSearch, + setSearchAccount, showSearch, + submitSearch, } from 'soapbox/actions/search'; import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input'; import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; @@ -53,9 +54,9 @@ const Search = (props: ISearch) => { const value = useAppSelector((state) => state.search.value); const submitted = useAppSelector((state) => state.search.submitted); - const debouncedSubmit = debounce(() => { + const debouncedSubmit = useCallback(debounce(() => { dispatch(submitSearch()); - }, 900); + }, 900), []); const handleChange = (event: React.ChangeEvent) => { const { value } = event.target; @@ -76,10 +77,13 @@ const Search = (props: ISearch) => { }; const handleSubmit = () => { - dispatch(submitSearch()); - if (openInRoute) { + dispatch(setSearchAccount(null)); + dispatch(submitSearch()); + history.push('/search'); + } else { + dispatch(submitSearch()); } }; diff --git a/app/soapbox/reducers/search.ts b/app/soapbox/reducers/search.ts index 4f22a9bb3..eb2c1ed8d 100644 --- a/app/soapbox/reducers/search.ts +++ b/app/soapbox/reducers/search.ts @@ -123,6 +123,7 @@ export default function search(state = ReducerRecord(), action: AnyAction) { case SEARCH_EXPAND_SUCCESS: return paginateResults(state, action.searchType, action.results, action.searchTerm); case SEARCH_ACCOUNT_SET: + if (!action.accountId) return state.set('accountId', null); return ReducerRecord({ accountId: action.accountId, filter: 'statuses' }); default: return state;