Skip to content

Commit

Permalink
Merge branch 'master' into quochuy-show_content_edited
Browse files Browse the repository at this point in the history
  • Loading branch information
roadscape committed May 21, 2019
2 parents 06b9ca9 + f0f7a1d commit c74afb2
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 327 deletions.
162 changes: 88 additions & 74 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,96 +73,110 @@
},
"gpt_enabled": null,
"gpt_basic_slots": {
"top_nav_premium": {
"slot_id": "div-gpt-ad-1548778664403-0",
"args": ["/21784675435/steemit_top-navi", [[220, 90], [728, 90], [970, 90]], "div-gpt-ad-1548778664403-0"],
"kind": "basic"
},
"top_nav": {
"slot_id": "div-gpt-ad-1548778612404-0",
"args": ["/21784675435/steemit_premium_top-navi", [[970, 90], [728, 90], [220, 90]], "div-gpt-ad-1548778612404-0"],
"kind": "basic"
},
"left_nav_premium": {
"slot_id": "div-gpt-ad-1548778771262-0",
"args": ["/21784675435/steemit_premium_left-navigation", [[125, 125], [120, 90], [120, 600], [120, 60], [160, 600], [120, 240]], "div-gpt-ad-1548778771262-0"],
"kind": "basic"
},
"left_nav": {
"slot_id": "div-gpt-ad-1548778799404-0",
"args": ["/21784675435/steemit_left-navigation", [[160, 600], [120, 240], [120, 600], [120, 60], [125, 125], [120, 90]], "div-gpt-ad-1548778799404-0"],
"kind": "basic"
},
"right_nav": {
"slot_id": "div-gpt-ad-1548778861089-0",
"args": ["/21784675435/steemit_right-navigation", [[120, 600], [120, 60], [125, 125], [120, 240], [160, 600], [120, 90]], "div-gpt-ad-1548778861089-0"],
"kind": "basic"
},
"bottom_post": {
"slot_id": "div-gpt-ad-1553686705417-0",
"args": ["/21784675435/steemit_bottom-of-post", [[300, 100], [234, 60], [728, 90], [220, 90], [970, 90], [336, 280], [890, 222], [320, 50], [468, 60]], "div-gpt-ad-1553686705417-0"]
},
"basic_bottom_post": {
"slot_id": "div-gpt-ad-1553686705417-0",
"args": ["/21784675435/steemit_bottom-of-post", [[300, 100], [234, 60], [728, 90], [220, 90], [970, 90], [336, 280], [890, 222], [320, 50], [468, 60]], "div-gpt-ad-1553686705417-0"]
},
"in_feed": {
"slot_id": "div-gpt-ad-1548778917304-0",
"args": ["/21784675435/steemit_in-feed", [[728, 90], [300, 100], [890, 222], [468, 60], [970, 90], [336, 280], [234, 60]], "div-gpt-ad-1548778917304-0"],
"kind": "basic"
}
},
"gpt_category_slots": {
"cryptocurrency": {
"top_nav": {
"slot_id": "div-gpt-ad-1550891917103-0",
"args": ["/21784675435/steemit_top-navi/steemit_top-navi_cryptocurrency", [[728, 90], [220, 90], [970, 90]], "div-gpt-ad-1550891917103-0"],
"kind": "category"
},
"right_nav": {
"slot_id": "div-gpt-ad-1550892019550-0",
"args": ["/21784675435/steemit_right-navigation/steemit_right-navigation_cryptocurrency", [[120, 90], [120, 240], [120, 60], [160, 600], [120, 600], [125, 125]], "div-gpt-ad-1550892019550-0"],
"kind": "category"
},
"left_nav": {
"slot_id": "div-gpt-ad-1550892097245-0",
"args": ["/21784675435/steemit_left-navigation/steemit_left-navigation_cryptocurrency", [[120, 240], [120, 600], [125, 125], [120, 90], [160, 600], [120, 60]], "div-gpt-ad-1550892097245-0"],
"kind": "category"
},
"bottom_post": {
"slot_id": "div-gpt-ad-1550892163180-0",
"args": ["/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_cryptocurrency", [[336, 280], [320, 50], [468, 60], [970, 90], [890, 222], [300, 100], [728, 90], [234, 60]], "div-gpt-ad-1550892163180-0"],
"kind": "category"
}
"bottom-of-post": {
"path": "/21784675435/steemit_bottom-of-post",
"dimensions": [[728, 90], [970, 90]]
},
"bottom-of-post-mobile": {
"path": "/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_mobile",
"dimensions": [[220, 90]]
},

"left-navigation": {
"path": "/21784675435/steemit_left-navigation",
"dimensions": [[120, 600], [160, 600]]
},
"left-navigation-loggedin-mobile": {
"path": "/21784675435/steemit_left-navigation/steemit_left-navigation_loggedin_mobile",
"dimensions": [[120, 240]]
},
"left-navigation-loggedin": {
"path": "/21784675435/steemit_left-navigation/steemit_left-navigation_loggedin",
"dimensions": [[120, 600], [160, 600]]
},
"left-navigation-mobile": {
"path": "/21784675435/steemit_left-navigation/steemit_left-navigation_mobile",
"dimensions": [[120, 240]]
},

"right-navigation": {
"path": "/21784675435/steemit_right-navigation",
"dimensions": [[120, 600], [160, 600]]
},
"right-navigation-loggedin-mobile": {
"path": "/21784675435/steemit_right-navigation/steemit_right-navigation_loggedin_mobile",
"dimensions": [[120, 240]]
},
"right-navigation-loggedin": {
"path": "/21784675435/steemit_right-navigation/steemit_right-navigation_loggedin",
"dimensions": [[120, 600], [160, 600]]
},
"right-navigation-mobile": {
"path": "/21784675435/steemit_right-navigation/steemit_right-navigation_mobile",
"dimensions": [[120, 240]]
},

"top-navigation": {
"path": "/21784675435/steemit_top-navi",
"dimensions": [[728, 90], [970, 90]]
},
"top-navigation-loggedin-mobile": {
"path": "/21784675435/steemit_top-navi/steemit_top-navi_loggedin_mobile",
"dimensions": [[220, 90]]
},
"top-navigation-loggedin": {
"path": "/21784675435/steemit_top-navi/steemit_top-navi_loggedin",
"dimensions": [[728, 90], [970, 90]]
},
"top-navigation-mobile": {
"path": "/21784675435/steemit_top-navi/steemit_top-navi_mobile",
"dimensions": [[220, 90]]
}
},
"gpt_category_slots": {},
"gpt_bidding_slots":{
"left_nav_2": {
"slot_id": "div-gpt-ad-1554687231046-0",
"args": ["/21784675435/steemit_left-navigation/steemit_left-navigation_prebid", [[120, 600],[160,600]], "div-gpt-ad-1554687231046-0"],
"kind": "bidding"
},
"bottom_post": {
"slot_id": "div-gpt-ad-1551233873698-0",
"args": ["/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_prebid", [[728, 90], [320, 50], [234, 60], [336, 280], [970, 90], [468, 60], [300, 100], [890, 222]], "div-gpt-ad-1551233873698-0"],
"kind": "bidding"
"bottom-of-post": {
"path": "/21784675435/steemit_bottom-of-post/steemit_bottom-of-post_prebid",
"dimensions": [[728, 90]]
},

"post-page-above-comments": {
"path": "/21784675435/steemit_post-page-above-comments",
"dimensions": [[728, 90], [970, 90]]
},
"post-page-above-comments-loggedin-mobile": {
"path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_loggedin_mobile",
"dimensions": [[220, 90]]
},
"post-page-above-comments-loggedin": {
"path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_loggedin",
"dimensions": [[728, 90], [970, 90]]
},
"post-page-above-comments-mobile": {
"path": "/21784675435/steemit_post-page-above-comments/steemit_post-page-above-comments_mobile",
"dimensions": [[220, 90]]
},

"left-navigation": {
"path": "/21784675435/steemit_left-navigation/steemit_left-navigation_prebid",
"dimensions": [[120, 600], [160, 600]]
}
},
"gpt_bidding": {
"prebid_timeout": 2000,
"failsafe_timeout": 3000,
"ad_units": [
{
"code": "div-gpt-ad-1551233873698-0",
"mediaTypes": { "banner": { "sizes": [728, 90] } },
"code": "/21784675435/steemit_post-page-above-comments",
"mediaTypes": { "banner": { "sizes": [[728, 90], [220, 90], [970, 90]] } },
"bids": [{
"bidder": "coinzilla",
"params": { "placementId": "6425c7b9886e0045972" }
}]
},
{
"code": "div-gpt-ad-1551234081752-0",
"mediaTypes": { "banner": { "sizes": [160, 600] } },
"code": "/21784675435/steemit_left-navigation/steemit_left-navigation_prebid",
"mediaTypes": { "banner": { "sizes": [[120, 600], [160, 600]] } },
"bids": [{
"bidder": "coinzilla",
"params": { "placementId": "3575c7b9886e2cb3619" }
Expand Down
18 changes: 18 additions & 0 deletions src/app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,30 @@ class App extends React.Component {
this.setState({ gptBannerHeight: height });
}

toggleBodyNightmode(nightmodeEnabled) {
if (nightmodeEnabled) {
document.body.classList.remove('theme-light');
document.body.classList.add('theme-dark');
} else {
document.body.classList.remove('theme-dark');
document.body.classList.add('theme-light');
}
}

componentWillReceiveProps(nextProps) {
const { nightmodeEnabled } = nextProps;
this.toggleBodyNightmode(nightmodeEnabled);
}

componentWillMount() {
if (process.env.BROWSER) localStorage.removeItem('autopost'); // July 14 '16 compromise, renamed to autopost2
this.props.loginUser();
}

componentDidMount() {
const { nightmodeEnabled } = this.props;
this.toggleBodyNightmode(nightmodeEnabled);

window.addEventListener('gptadshown', this.gptadshownListener);
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/components/elements/AuthorDropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
clear: both;
font-size: 90%;
padding-top: 15px;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
112 changes: 78 additions & 34 deletions src/app/components/elements/BiddingAd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,107 @@ import { connect } from 'react-redux';

class BiddingAd extends Component {
componentDidMount() {
window.addEventListener('prebidNoBids', this.prebidNoBids);
const id = this.id;
googletag.cmd.push(function() {
console.log(
'BiddingAd::componentDidMount::2nd googletag push with display'
if (!this.ad.path || !this.enabled) return;

googletag.cmd.push(() => {
const slot = googletag.defineSlot(
this.ad.path,
this.ad.dimensions,
this.ad.path
);
googletag.display(id);
});
}

componentWillUnmount() {
window.removeEventListener('prebidNoBids', this.prebidNoBids);
if (slot) {
slot.addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();

googletag.cmd.push(() => {
googletag.display(this.ad.path);
this.refreshBid(this.ad.path, slot);
});
}
});
}

prebidNoBids(e) {
console.log('Received a NOBIDS event', e, this.state);
if (e.slotId === this.id) {
console.log('Will hide this ad based on event match id', e);
this.setState({ shown: false });
}
refreshBid(path, slot) {
pbjs.que.push(() => {
pbjs.requestBids({
timeout: 2000,
adUnitCodes: [path],
bidsBackHandler: function() {
pbjs.setTargetingForGPTAsync([path]);
googletag.pubads().refresh([slot]);
},
});
});
}

constructor(props) {
super(props);
this.id = this.props.id;
this.state = { shown: true };
const { ad, enabled, type } = props;

this.prebidNoBids = this.prebidNoBids.bind(this);
}
this.ad = {};
this.type = type;
this.enabled = false;

render() {
console.log('BiddingAd::render');
if (this.state.shown) {
console.log('WILL SHOW A BIDDING AD!!!!!!!!!!!!!!!!!');
return (
<div className="bidding-ad gpt-ad" style={{ width: '100%' }}>
<div id={this.id} />
</div>
);
if (ad) {
// console.info(
// `Slot named '${props.slotName}' will render with given data:`,
// ad
// );
this.enabled = enabled;
this.ad = ad.toJS();
} else {
// TODO: One Day we will fall back to another ad type here.
console.log('NO AD TO SHOW!');
return null;
// console.info(
// `Slot named '${
// props.slotName
// }' will be disabled because we were unable to find the ad details.`
// );
}
}

render() {
return (
<div
className="bidding-ad gpt-ad"
style={{ width: '100%' }}
id={this.ad.path}
/>
);
}
}

BiddingAd.propTypes = {
id: PropTypes.string.isRequired, // TODO: This is the naive way, make this better with a sensible config.
ad: PropTypes.shape({
path: PropTypes.string,
dimensions: PropTypes.array,
}).isRequired,
enabled: PropTypes.bool.isRequired,
type: PropTypes.oneOf(['Bidding', 'Category', 'Basic']),
};

export default connect(
(state, props) => {
console.log('GptBidding::connect', props);
const enabled =
!!state.app.getIn(['googleAds', 'gptEnabled']) &&
!!process.env.BROWSER &&
!!window.googletag;
const postCategory = state.global.get('postCategory');
const basicSlots = state.app.getIn(['googleAds', `gptBasicSlots`]);
const biddingSlots = state.app.getIn(['googleAds', `gptBiddingSlots`]);
const categorySlots = state.app.getIn([
'googleAds',
`gptCategorySlots`,
]);

const slotName = props.slotName;
let type = props.type;
let slot = state.app.getIn(['googleAds', `gpt${type}Slots`, slotName]);
console.log('Found slot for type', type, slot);

return {
enabled,
ad: slot,
...props,
};
},
Expand Down
Loading

0 comments on commit c74afb2

Please sign in to comment.