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
This commit is contained in:
commit
0f4a755693
3 changed files with 12 additions and 7 deletions
|
@ -158,7 +158,7 @@ const showSearch = () => ({
|
|||
type: SEARCH_SHOW,
|
||||
});
|
||||
|
||||
const setSearchAccount = (accountId: string) => ({
|
||||
const setSearchAccount = (accountId: string | null) => ({
|
||||
type: SEARCH_ACCOUNT_SET,
|
||||
accountId,
|
||||
});
|
||||
|
|
|
@ -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<HTMLInputElement>) => {
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue