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