Ad: premium+ check (1589)

This commit is contained in:
infinite-persistence 2022-05-30 14:17:01 +08:00
commit 530433b508
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 16 additions and 7 deletions

View file

@ -15,11 +15,17 @@ export default function useShouldShowAds(
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
function resolveAdVisibility() {
// 'ad_blocker_detected' will be undefined at startup. Wait until we are
// sure it is not blocked (i.e. === false) before showing the component.
return ad_blocker_detected === false && SHOW_ADS && !hasPremiumPlus && (NO_COUNTRY_CHECK || userCountry === 'US');
// 'ad_blocker_detected' and 'hasPremiumPlus' will be undefined until
// fetched. Only show when it is exactly 'false'.
return (
SHOW_ADS &&
(NO_COUNTRY_CHECK || userCountry === 'US') &&
ad_blocker_detected === false &&
hasPremiumPlus === false
);
}
// -- Check for ad-blockers
React.useEffect(() => {
if (ad_blocker_detected === undefined) {
let mounted = true;
@ -46,5 +52,10 @@ export default function useShouldShowAds(
}
}, []);
// --- Check for Premium+
React.useEffect(() => {
setShouldShowAds(resolveAdVisibility());
}, [hasPremiumPlus]);
return shouldShowAds;
}

View file

@ -189,10 +189,8 @@ function HomePage(props: Props) {
label={__('View More')}
/>
)}
{isMobileScreen && !hasPremiumPlus && <AdsBanner key={`${currentTheme}:${title}`} />}
{!isMobileScreen && !hasPremiumPlus && (index === 0 || index % 2 === 0) && (
<AdsBanner key={`${currentTheme}:${title}`} />
)}
{isMobileScreen && <AdsBanner key={`${currentTheme}:${title}`} />}
{!isMobileScreen && (index === 0 || index % 2 === 0) && <AdsBanner key={`${currentTheme}:${title}`} />}
</>
)}
</div>