Global Search: Run throttled checkSearchPostsFlood (#6396)
This commit is contained in:
parent
df263291da
commit
876478ac36
@ -10,6 +10,7 @@ import {
|
||||
import { selectIsCurrentUserPremium } from '../../../global/selectors';
|
||||
import buildClassName from '../../../util/buildClassName';
|
||||
import { formatStarsAsIcon } from '../../../util/localization/format';
|
||||
import { throttle } from '../../../util/schedulers';
|
||||
import { getServerTime } from '../../../util/serverTime';
|
||||
import { LOCAL_TGS_PREVIEW_URLS, LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets';
|
||||
|
||||
@ -39,6 +40,7 @@ type StateProps = {
|
||||
};
|
||||
|
||||
const WAIT_DELAY = 2;
|
||||
const runThrottled = throttle((cb) => cb(), 500, false);
|
||||
|
||||
const PublicPostsSearchLauncher = ({
|
||||
searchQuery,
|
||||
@ -48,6 +50,12 @@ const PublicPostsSearchLauncher = ({
|
||||
isCurrentUserPremium,
|
||||
starsBalance,
|
||||
}: OwnProps & StateProps) => {
|
||||
const {
|
||||
checkSearchPostsFlood,
|
||||
openPremiumModal,
|
||||
openStarsBalanceModal,
|
||||
} = getActions();
|
||||
|
||||
const lang = useLang();
|
||||
const queryIsFree = searchFlood?.queryIsFree;
|
||||
const queryFromFlood = searchFlood?.query;
|
||||
@ -79,11 +87,13 @@ const PublicPostsSearchLauncher = ({
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
checkSearchPostsFlood,
|
||||
openPremiumModal,
|
||||
openStarsBalanceModal,
|
||||
} = getActions();
|
||||
useEffect(() => {
|
||||
if (searchQuery && queryFromFlood !== searchQuery) {
|
||||
runThrottled(() => {
|
||||
checkSearchPostsFlood({ query: searchQuery });
|
||||
});
|
||||
}
|
||||
}, [searchQuery, queryFromFlood]);
|
||||
|
||||
const onCheckFlood = useLastCallback(() => {
|
||||
checkSearchPostsFlood({});
|
||||
|
||||
@ -16,8 +16,6 @@ addActionHandler('setGlobalSearchQuery', (global, actions, payload): ActionRetur
|
||||
&& currentContent !== GlobalSearchContent.BotApps && currentContent !== GlobalSearchContent.PublicPosts
|
||||
? { chats: !chatId, messages: true } : undefined;
|
||||
|
||||
actions.checkSearchPostsFlood({ query, tabId });
|
||||
|
||||
return updateGlobalSearch(global, {
|
||||
globalResults: {},
|
||||
localResults: {},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user