Gifts: Hotfix (#5545)

This commit is contained in:
zubiden 2025-01-28 01:07:02 +01:00 committed by Alexander Zinchuk
parent 4c1e8b52ba
commit a323496937
2 changed files with 16 additions and 9 deletions

View File

@ -17,6 +17,7 @@ import { getPeerTitle, getUserFullName } from '../../../global/helpers';
import { isApiPeerChat, isApiPeerUser } from '../../../global/helpers/peers';
import { selectPeer } from '../../../global/selectors';
import buildClassName from '../../../util/buildClassName';
import { throttle } from '../../../util/schedulers';
import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev';
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';
@ -56,6 +57,9 @@ type StateProps = {
const AVATAR_SIZE = 100;
const INTERSECTION_THROTTLE = 200;
const SCROLL_THROTTLE = 200;
const runThrottledForScroll = throttle((cb) => cb(), SCROLL_THROTTLE, true);
const PremiumGiftModal: FC<OwnProps & StateProps> = ({
modal,
@ -133,21 +137,25 @@ const PremiumGiftModal: FC<OwnProps & StateProps> = ({
if (!isOpen) {
setIsHeaderHidden(true);
setSelectedGift(undefined);
setSelectedCategory('all');
}
}, [isOpen]);
const handleScroll = useLastCallback((e: React.UIEvent<HTMLDivElement>) => {
if (selectedGift) return;
const currentTarget = e.currentTarget;
const { scrollTop } = e.currentTarget;
runThrottledForScroll(() => {
const { scrollTop } = currentTarget;
setIsHeaderHidden(scrollTop <= 150);
setIsHeaderHidden(scrollTop <= 150);
if (transitionRef.current && giftHeaderRef.current) {
const { top: headerTop } = giftHeaderRef.current.getBoundingClientRect();
const { top: transitionTop } = transitionRef.current.getBoundingClientRect();
setIsHeaderForStarGifts(headerTop - transitionTop <= 0);
}
if (transitionRef.current && giftHeaderRef.current) {
const { top: headerTop } = giftHeaderRef.current.getBoundingClientRect();
const { top: transitionTop } = transitionRef.current.getBoundingClientRect();
setIsHeaderForStarGifts(headerTop - transitionTop <= 0);
}
});
});
const giftPremiumDescription = lang('GiftPremiumDescription', {

View File

@ -16,9 +16,8 @@ export function selectPeerPhotos<T extends GlobalState>(global: T, peerId: strin
export function selectCanGift<T extends GlobalState>(global: T, peerId: string) {
const bot = selectBot(global, peerId);
const user = selectUser(global, peerId);
const chat = selectChat(global, peerId);
const areStarGiftsAvailable = chat ? selectChatFullInfo(global, peerId)?.areStarGiftsAvailable : user;
const areStarGiftsAvailable = selectChatFullInfo(global, peerId)?.areStarGiftsAvailable || user;
return Boolean(!selectIsPremiumPurchaseBlocked(global) && !bot && peerId !== SERVICE_NOTIFICATIONS_USER_ID
&& areStarGiftsAvailable);