Skip to content

Commit

Permalink
[docs] Reduce diffs, isolate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 2, 2019
1 parent 2c5ba7e commit e5df4c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
66 changes: 33 additions & 33 deletions docs/src/modules/components/Ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const styles = theme => ({
},
});

function getAdblockCount() {
const seen = getCookie('adblockCount');
return seen === '' ? 0 : parseInt(seen, 10);
}

function getAdblock(classes, t) {
return (
<Paper component="span" elevation={0} className={classes.paper}>
Expand Down Expand Up @@ -70,16 +65,22 @@ const inHouses = [
function Ad(props) {
const { classes } = props;
const { current: random } = React.useRef(Math.random());
const timerAdblock = React.useRef();
const t = useSelector(state => state.options.t);

const timerAdblock = React.useRef();
const [adblock, setAdblock] = React.useState(null);
const [carbonOut, setCarbonOut] = React.useState(null);

const checkAdblock = React.useCallback((attempt = 1) => {
if (
document.querySelector('.cf-wrapper') ||
document.querySelector('#carbonads') ||
document.querySelector('#in-house')
) {
if (document.querySelector('.cf-wrapper') || document.querySelector('#carbonads')) {
if (
document.querySelector('#carbonads a') &&
document.querySelector('#carbonads a').getAttribute('href') ===
'https://material-ui-next.com/discover-more/backers'
) {
setCarbonOut(true);
}

setAdblock(false);
return;
}
Expand All @@ -88,8 +89,6 @@ function Ad(props) {
timerAdblock.current = setTimeout(() => {
checkAdblock(attempt + 1);
}, 500);
} else {
document.cookie = `adblockCount=${getAdblockCount() + 1};path=/`;
}

if (attempt > 6) {
Expand All @@ -113,33 +112,34 @@ function Ad(props) {
return null;
}

if (disable) {
return <span className={classes.root}>{getAdblock(classes, t)}</span>;
}
let children;

if (getAdblockCount() >= 2) {
return (
<span className={classes.root} style={{ minHeight: 'auto' }}>
<AdInHouse ad={inHouses[Math.round((inHouses.length - 1) * Math.random())]} />
</span>
);
if (adblock) {
children = <AdInHouse ad={inHouses[Math.round((inHouses.length - 1) * random)]} />;
}

if (adblock === true) {
return <span className={classes.root}>{getAdblock(classes, t)}</span>;
if (disable) {
children = getAdblock(classes, t);
}

let randomAd;

if (random < 0.6) {
randomAd = <AdCodeFund />;
} else if (random < 0.63) {
randomAd = <AdInHouse ad={inHouses[0]} />;
} else {
randomAd = <AdCarbon />;
if (!children) {
if (random >= 0.6) {
children = <AdCodeFund />;
} else if (!carbonOut) {
children = <AdCarbon />;
} else {
children = <AdInHouse ad={inHouses[Math.round((inHouses.length - 1) * random)]} />;
}
}

return <span className={classes.root}>{randomAd}</span>;
return (
<span
className={classes.root}
style={{ minHeight: children.type === 'AdInHouse' ? 'auto' : null }}
>
{children}
</span>
);
}

Ad.propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const pages = [
},
],
},
{ pathname: 'https://material-ui.com/versions', displayNav: false },
{ pathname: '/versions', displayNav: false },
{ pathname: '/', displayNav: false, title: false },
];

Expand Down

0 comments on commit e5df4c9

Please sign in to comment.