Skip to content

Commit

Permalink
TW-1585 Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
keshan3262 committed Dec 6, 2024
1 parent cbc5ed5 commit 18c4a0d
Showing 1 changed file with 123 additions and 120 deletions.
243 changes: 123 additions & 120 deletions src/app/templates/partners-promotion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,126 +38,129 @@ const shouldBeHiddenTemporarily = (hiddenAt: number) => {
return Date.now() - hiddenAt < AD_HIDING_TIMEOUT;
};

export const PartnersPromotion = memo<PartnersPromotionProps>(({ variant, id, pageName, withPersonaProvider }) => {
const isImageAd = variant === PartnersPromotionVariant.Image;
const adsViewerAddress = useAdsViewerPkh();
const dispatch = useDispatch();
const hiddenAt = usePromotionHidingTimestampSelector(id);
const shouldShowPartnersPromo = useShouldShowPartnersPromoSelector();

const isAnalyticsSentRef = useRef(false);

const [hovered, setHovered, setUnhovered] = useBooleanState(false);
const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(shouldBeHiddenTemporarily(hiddenAt));
const [providerName, setProviderName] = useState<AdsProviderLocalName>('Optimal');
const [adError, setAdError] = useState(false);
const [adIsReady, setAdIsReady] = useState(false);

useEffect(() => {
const newIsHiddenTemporarily = shouldBeHiddenTemporarily(hiddenAt);
setIsHiddenTemporarily(newIsHiddenTemporarily);

if (newIsHiddenTemporarily) {
const timeout = setTimeout(
() => setIsHiddenTemporarily(false),
Math.max(Date.now() - hiddenAt + AD_HIDING_TIMEOUT, 0)
);

return () => clearTimeout(timeout);
export const PartnersPromotion = memo<PartnersPromotionProps>(
({ variant, id, pageName, withPersonaProvider, className }) => {
const isImageAd = variant === PartnersPromotionVariant.Image;
const adsViewerAddress = useAdsViewerPkh();
const dispatch = useDispatch();
const hiddenAt = usePromotionHidingTimestampSelector(id);
const shouldShowPartnersPromo = useShouldShowPartnersPromoSelector();

const isAnalyticsSentRef = useRef(false);

const [hovered, setHovered, setUnhovered] = useBooleanState(false);
const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(shouldBeHiddenTemporarily(hiddenAt));
const [providerName, setProviderName] = useState<AdsProviderLocalName>('Optimal');
const [adError, setAdError] = useState(false);
const [adIsReady, setAdIsReady] = useState(false);

useEffect(() => {
const newIsHiddenTemporarily = shouldBeHiddenTemporarily(hiddenAt);
setIsHiddenTemporarily(newIsHiddenTemporarily);

if (newIsHiddenTemporarily) {
const timeout = setTimeout(
() => setIsHiddenTemporarily(false),
Math.max(Date.now() - hiddenAt + AD_HIDING_TIMEOUT, 0)
);

return () => clearTimeout(timeout);
}

return;
}, [hiddenAt]);

const handleAdRectSeen = useCallback(() => {
if (isAnalyticsSentRef.current) return;

postAdImpression(adsViewerAddress, AdsProviderTitle[providerName], { pageName });

isAnalyticsSentRef.current = true;
}, [providerName, pageName, adsViewerAddress]);

const handleClosePartnersPromoClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
e => {
e.preventDefault();
e.stopPropagation();
dispatch(hidePromotionAction({ timestamp: Date.now(), id }));
},
[id, dispatch]
);

const handleOptimalError = useCallback(() => setProviderName('HypeLab'), []);
const handleHypelabError = useCallback(
() => (withPersonaProvider ? setProviderName('Persona') : setAdError(true)),
[withPersonaProvider]
);
const handlePersonaError = useCallback(() => setAdError(true), []);

const handleAdReady = useCallback(() => setAdIsReady(true), []);

if (!shouldShowPartnersPromo || adError || isHiddenTemporarily) {
return null;
}

return;
}, [hiddenAt]);

const handleAdRectSeen = useCallback(() => {
if (isAnalyticsSentRef.current) return;

postAdImpression(adsViewerAddress, AdsProviderTitle[providerName], { pageName });

isAnalyticsSentRef.current = true;
}, [providerName, pageName, adsViewerAddress]);

const handleClosePartnersPromoClick = useCallback<MouseEventHandler<HTMLButtonElement>>(
e => {
e.preventDefault();
e.stopPropagation();
dispatch(hidePromotionAction({ timestamp: Date.now(), id }));
},
[id, dispatch]
);

const handleOptimalError = useCallback(() => setProviderName('HypeLab'), []);
const handleHypelabError = useCallback(
() => (withPersonaProvider ? setProviderName('Persona') : setAdError(true)),
[withPersonaProvider]
);
const handlePersonaError = useCallback(() => setAdError(true), []);

const handleAdReady = useCallback(() => setAdIsReady(true), []);

if (!shouldShowPartnersPromo || adError || isHiddenTemporarily) {
return null;
return (
<div
className={clsx(
'w-full relative flex flex-col items-center',
!adIsReady && (isImageAd ? 'min-h-[101px]' : 'min-h-16'),
className
)}
onMouseEnter={setHovered}
onMouseLeave={setUnhovered}
>
{(() => {
switch (providerName) {
case 'Optimal':
return (
<OptimalPromotion
accountPkh={adsViewerAddress}
variant={variant}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handleOptimalError}
/>
);
case 'HypeLab':
return (
<HypelabPromotion
accountPkh={adsViewerAddress}
variant={variant}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handleHypelabError}
/>
);
case 'Persona':
return (
<PersonaPromotion
accountPkh={adsViewerAddress}
id={id}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handlePersonaError}
/>
);
}
})()}

{!adIsReady && (
<div className="absolute inset-0 bg-grey-4 text-secondary flex justify-center items-center rounded-lg">
<span className="text-font-description-bold text-grey-2">
<T id="thanksForSupportingTemple" />
</span>
</div>
)}

{hovered && <CloseButton onClick={handleClosePartnersPromoClick} />}
</div>
);
}

return (
<div
className={clsx(
'w-full relative flex flex-col items-center',
!adIsReady && (isImageAd ? 'min-h-[101px]' : 'min-h-16')
)}
onMouseEnter={setHovered}
onMouseLeave={setUnhovered}
>
{(() => {
switch (providerName) {
case 'Optimal':
return (
<OptimalPromotion
accountPkh={adsViewerAddress}
variant={variant}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handleOptimalError}
/>
);
case 'HypeLab':
return (
<HypelabPromotion
accountPkh={adsViewerAddress}
variant={variant}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handleHypelabError}
/>
);
case 'Persona':
return (
<PersonaPromotion
accountPkh={adsViewerAddress}
id={id}
isVisible={adIsReady}
pageName={pageName}
onAdRectSeen={handleAdRectSeen}
onReady={handleAdReady}
onError={handlePersonaError}
/>
);
}
})()}

{!adIsReady && (
<div className="absolute inset-0 bg-grey-4 text-secondary flex justify-center items-center rounded-lg">
<span className="text-font-description-bold text-grey-2">
<T id="thanksForSupportingTemple" />
</span>
</div>
)}

{hovered && <CloseButton onClick={handleClosePartnersPromoClick} />}
</div>
);
});
);

0 comments on commit 18c4a0d

Please sign in to comment.