kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Add token from search input into search
rodzic
4c32ab9f8a
commit
c1a1065267
|
@ -17,6 +17,7 @@ import {
|
||||||
import AutosuggestAccountInput from 'soapbox/components/autosuggest-account-input.tsx';
|
import AutosuggestAccountInput from 'soapbox/components/autosuggest-account-input.tsx';
|
||||||
import Input from 'soapbox/components/ui/input.tsx';
|
import Input from 'soapbox/components/ui/input.tsx';
|
||||||
import SvgIcon from 'soapbox/components/ui/svg-icon.tsx';
|
import SvgIcon from 'soapbox/components/ui/svg-icon.tsx';
|
||||||
|
import { useSearchTokens } from 'soapbox/features/explore/useSearchTokens.ts';
|
||||||
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
||||||
import { useAppSelector } from 'soapbox/hooks/useAppSelector.ts';
|
import { useAppSelector } from 'soapbox/hooks/useAppSelector.ts';
|
||||||
import { selectAccount } from 'soapbox/selectors/index.ts';
|
import { selectAccount } from 'soapbox/selectors/index.ts';
|
||||||
|
@ -56,6 +57,7 @@ const Search = (props: ISearch) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
|
const { addToken } = useSearchTokens();
|
||||||
|
|
||||||
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);
|
||||||
|
@ -85,11 +87,12 @@ const Search = (props: ISearch) => {
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
if (openInRoute) {
|
if (openInRoute) {
|
||||||
|
addToken(value);
|
||||||
dispatch(setSearchAccount(null));
|
dispatch(setSearchAccount(null));
|
||||||
dispatch(submitSearch());
|
dispatch(submitSearch());
|
||||||
|
|
||||||
history.push('/explore');
|
history.push('/explore');
|
||||||
} else {
|
} else {
|
||||||
|
addToken(value);
|
||||||
dispatch(submitSearch());
|
dispatch(submitSearch());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,18 +17,22 @@ export const useSearchTokens = create<SearchTokensState>()(
|
||||||
tokens: new Set(),
|
tokens: new Set(),
|
||||||
|
|
||||||
addToken(token: string): void {
|
addToken(token: string): void {
|
||||||
setState((state) => {
|
if (token) {
|
||||||
return produce(state, (draft) => {
|
setState((state) => {
|
||||||
draft.tokens.add(token);
|
return produce(state, (draft) => {
|
||||||
|
draft.tokens.add(token);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addTokens(tokens: string[]): void {
|
addTokens(tokens: string[]): void {
|
||||||
setState((state) => {
|
setState((state) => {
|
||||||
return produce(state, (draft) => {
|
return produce(state, (draft) => {
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
draft.tokens.add(token);
|
if (token) {
|
||||||
|
draft.tokens.add(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue