resolveAdVisibility: wait for premium+ (a fetched status)
This commit is contained in:
parent
bd7d2ad621
commit
7dc9c983f8
1 changed files with 14 additions and 3 deletions
|
@ -15,11 +15,17 @@ export default function useShouldShowAds(
|
||||||
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
|
const [shouldShowAds, setShouldShowAds] = React.useState(resolveAdVisibility());
|
||||||
|
|
||||||
function resolveAdVisibility() {
|
function resolveAdVisibility() {
|
||||||
// 'ad_blocker_detected' will be undefined at startup. Wait until we are
|
// 'ad_blocker_detected' and 'hasPremiumPlus' will be undefined until
|
||||||
// sure it is not blocked (i.e. === false) before showing the component.
|
// fetched. Only show when it is exactly 'false'.
|
||||||
return ad_blocker_detected === false && SHOW_ADS && !hasPremiumPlus && (NO_COUNTRY_CHECK || userCountry === 'US');
|
return (
|
||||||
|
SHOW_ADS &&
|
||||||
|
(NO_COUNTRY_CHECK || userCountry === 'US') &&
|
||||||
|
ad_blocker_detected === false &&
|
||||||
|
hasPremiumPlus === false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Check for ad-blockers
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (ad_blocker_detected === undefined) {
|
if (ad_blocker_detected === undefined) {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
|
@ -46,5 +52,10 @@ export default function useShouldShowAds(
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// --- Check for Premium+
|
||||||
|
React.useEffect(() => {
|
||||||
|
setShouldShowAds(resolveAdVisibility());
|
||||||
|
}, [hasPremiumPlus]);
|
||||||
|
|
||||||
return shouldShowAds;
|
return shouldShowAds;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue