pl-fe: remove accountSearch action

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2025-10-23 15:49:41 +02:00
parent a922287246
commit b7f7e3394b
2 changed files with 11 additions and 47 deletions

View File

@ -208,13 +208,6 @@ const updateNotificationSettings = (params: UpdateNotificationSettingsParams) =>
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState).settings.updateNotificationSettings(params).then((data) => ({ params, data }));
const accountSearch = (q: string, signal?: AbortSignal) =>
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).accounts.searchAccounts(q, { resolve: false, limit: 4, following: true }, { signal }).then((accounts) => {
dispatch(importEntities({ accounts }));
return accounts;
});
const accountLookup = (acct: string, signal?: AbortSignal) =>
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState()).accounts.lookupAccount(acct, { signal }).then((account) => {
@ -245,7 +238,6 @@ export {
pinAccount,
unpinAccount,
updateNotificationSettings,
accountSearch,
accountLookup,
biteAccount,
type AccountsAction,

View File

@ -1,13 +1,17 @@
import throttle from 'lodash/throttle';
import React, { useState, useRef, useCallback, useEffect } from 'react';
import React from 'react';
import { accountSearch } from 'pl-fe/actions/accounts';
import AutosuggestInput, { AutoSuggestion } from 'pl-fe/components/autosuggest-input';
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
import { useDebounce } from 'pl-fe/hooks/use-debounce';
import { useAccountSearch } from 'pl-fe/queries/search/use-search-accounts';
import type { Menu } from 'pl-fe/components/dropdown-menu';
import type { InputThemes } from 'pl-fe/components/ui/input';
const SEARCH_PARAMS = {
limit: 5,
resolve: false,
};
const noOp = () => { };
interface IAutosuggestAccountInput {
@ -30,31 +34,11 @@ const AutosuggestAccountInput: React.FC<IAutosuggestAccountInput> = ({
value = '',
...rest
}) => {
const dispatch = useAppDispatch();
const [accountIds, setAccountIds] = useState<Array<string>>([]);
const controller = useRef(new AbortController());
const refreshCancelToken = () => {
controller.current.abort();
controller.current = new AbortController();
};
const clearResults = () => {
setAccountIds([]);
};
const handleAccountSearch = useCallback(throttle((q) => {
dispatch(accountSearch(q, controller.current.signal))
.then((accounts: { id: string }[]) => {
const accountIds = accounts.map(account => account.id);
setAccountIds(accountIds);
})
.catch(noOp);
}, 900, { leading: true, trailing: true }), []);
// should ignore debounce on clearing input
const debouncedValue = useDebounce(value, 900);
const { data: accountIds = [] } = useAccountSearch(debouncedValue, SEARCH_PARAMS);
const handleChange: React.ChangeEventHandler<HTMLInputElement> = e => {
refreshCancelToken();
handleAccountSearch(e.target.value);
onChange(e);
};
@ -64,18 +48,6 @@ const AutosuggestAccountInput: React.FC<IAutosuggestAccountInput> = ({
}
};
useEffect(() => {
if (rest.autoFocus) {
handleAccountSearch('');
}
}, []);
useEffect(() => {
if (value === '') {
clearResults();
}
}, [value]);
return (
<AutosuggestInput
value={value}