Only call on not auth
And hide if auth
This commit is contained in:
parent
802b5d5a18
commit
7e605f60a2
1 changed files with 6 additions and 5 deletions
|
@ -16,8 +16,9 @@ let script;
|
||||||
|
|
||||||
export default function useAdOutbrain(hasPremiumPlus: boolean, isAuthenticated: boolean) {
|
export default function useAdOutbrain(hasPremiumPlus: boolean, isAuthenticated: boolean) {
|
||||||
// Only look at authentication for now. Eventually, we'll only use 'hasPremiumPlus'.
|
// Only look at authentication for now. Eventually, we'll only use 'hasPremiumPlus'.
|
||||||
const isAuthenticatedRef = React.useRef(isAuthenticated);
|
// Authenticated will return undefined if not yet populated, so wait and only show
|
||||||
isAuthenticatedRef.current = isAuthenticated;
|
// when returned as false
|
||||||
|
const isNotAuthenticated = isAuthenticated === false;
|
||||||
|
|
||||||
function loadListener() {
|
function loadListener() {
|
||||||
const container = window[OUTBRAIN_CONTAINER_KEY];
|
const container = window[OUTBRAIN_CONTAINER_KEY];
|
||||||
|
@ -30,7 +31,7 @@ export default function useAdOutbrain(hasPremiumPlus: boolean, isAuthenticated:
|
||||||
// after the stipulated time, well, no soup for you.
|
// after the stipulated time, well, no soup for you.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const filledAd = document.querySelector('.ob-widget-items-container');
|
const filledAd = document.querySelector('.ob-widget-items-container');
|
||||||
if (filledAd && !isAuthenticatedRef.current) {
|
if (filledAd && isNotAuthenticated) {
|
||||||
container.style.visibility = 'visible';
|
container.style.visibility = 'visible';
|
||||||
}
|
}
|
||||||
}, 5000); // 3s is sufficient for Chrome, but Firefox seems to take ~5s
|
}, 5000); // 3s is sufficient for Chrome, but Firefox seems to take ~5s
|
||||||
|
@ -38,7 +39,7 @@ export default function useAdOutbrain(hasPremiumPlus: boolean, isAuthenticated:
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!inIFrame() && !isAuthenticated && !script) {
|
if (!inIFrame() && isNotAuthenticated && !script) {
|
||||||
const loadTimer = setTimeout(() => {
|
const loadTimer = setTimeout(() => {
|
||||||
script = document.createElement('script');
|
script = document.createElement('script');
|
||||||
script.src = 'https://adncdnend.azureedge.net/adtags/odysee.adn.js';
|
script.src = 'https://adncdnend.azureedge.net/adtags/odysee.adn.js';
|
||||||
|
@ -52,7 +53,7 @@ export default function useAdOutbrain(hasPremiumPlus: boolean, isAuthenticated:
|
||||||
return () => clearTimeout(loadTimer);
|
return () => clearTimeout(loadTimer);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps, (on mount only)
|
// eslint-disable-next-line react-hooks/exhaustive-deps, (on mount only)
|
||||||
}, []);
|
}, [isNotAuthenticated]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isAuthenticated && window[OUTBRAIN_CONTAINER_KEY]) {
|
if (isAuthenticated && window[OUTBRAIN_CONTAINER_KEY]) {
|
||||||
|
|
Loading…
Reference in a new issue