Merge branch 'search-from-account' into 'develop'

Fix debounce in search, clear accountId on submit from navbar

See merge request soapbox-pub/soapbox-fe!1712
environments/review-develop-3zknud/deployments/720
marcin mikołajczak 2 years ago
commit 0f4a755693

@ -158,7 +158,7 @@ const showSearch = () => ({
type: SEARCH_SHOW, type: SEARCH_SHOW,
}); });
const setSearchAccount = (accountId: string) => ({ const setSearchAccount = (accountId: string | null) => ({
type: SEARCH_ACCOUNT_SET, type: SEARCH_ACCOUNT_SET,
accountId, accountId,
}); });

@ -1,7 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import { Map as ImmutableMap } from 'immutable'; import { Map as ImmutableMap } from 'immutable';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import * as React from 'react'; import React, { useCallback } from 'react';
import { defineMessages, useIntl } from 'react-intl'; import { defineMessages, useIntl } from 'react-intl';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
@ -9,8 +9,9 @@ import { useHistory } from 'react-router-dom';
import { import {
changeSearch, changeSearch,
clearSearch, clearSearch,
submitSearch, setSearchAccount,
showSearch, showSearch,
submitSearch,
} from 'soapbox/actions/search'; } from 'soapbox/actions/search';
import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input'; import AutosuggestAccountInput from 'soapbox/components/autosuggest_account_input';
import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; 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 value = useAppSelector((state) => state.search.value);
const submitted = useAppSelector((state) => state.search.submitted); const submitted = useAppSelector((state) => state.search.submitted);
const debouncedSubmit = debounce(() => { const debouncedSubmit = useCallback(debounce(() => {
dispatch(submitSearch()); dispatch(submitSearch());
}, 900); }, 900), []);
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target; const { value } = event.target;
@ -76,10 +77,13 @@ const Search = (props: ISearch) => {
}; };
const handleSubmit = () => { const handleSubmit = () => {
dispatch(submitSearch());
if (openInRoute) { if (openInRoute) {
dispatch(setSearchAccount(null));
dispatch(submitSearch());
history.push('/search'); history.push('/search');
} else {
dispatch(submitSearch());
} }
}; };

@ -123,6 +123,7 @@ export default function search(state = ReducerRecord(), action: AnyAction) {
case SEARCH_EXPAND_SUCCESS: case SEARCH_EXPAND_SUCCESS:
return paginateResults(state, action.searchType, action.results, action.searchTerm); return paginateResults(state, action.searchType, action.results, action.searchTerm);
case SEARCH_ACCOUNT_SET: case SEARCH_ACCOUNT_SET:
if (!action.accountId) return state.set('accountId', null);
return ReducerRecord({ accountId: action.accountId, filter: 'statuses' }); return ReducerRecord({ accountId: action.accountId, filter: 'statuses' });
default: default:
return state; return state;

Loading…
Cancel
Save