lbry-desktop/lbrytv/component/ads.jsx

71 lines
1.8 KiB
React
Raw Normal View History

2020-01-24 19:31:49 +01:00
// @flow
import * as PAGES from 'constants/pages';
2020-01-23 17:21:36 +01:00
import React, { useEffect } from 'react';
2020-01-24 19:31:49 +01:00
import { withRouter } from 'react-router';
import I18nMessage from 'component/i18nMessage';
import Button from 'component/button';
2020-01-23 17:21:36 +01:00
2020-01-24 19:31:49 +01:00
const ADS_URL = '//assets.revcontent.com/master/delivery.js';
type Props = {
location: { pathname: string },
};
function Ads(props: Props) {
const {
location: { pathname },
} = props;
2020-01-23 17:21:36 +01:00
useEffect(() => {
const script = document.createElement('script');
2020-01-24 19:31:49 +01:00
script.src = ADS_URL;
2020-01-23 17:21:36 +01:00
script.async = true;
2020-01-24 19:31:49 +01:00
// $FlowFixMe
2020-01-23 17:21:36 +01:00
document.body.appendChild(script);
return () => {
2020-01-24 19:31:49 +01:00
// $FlowFixMe
2020-01-23 17:21:36 +01:00
document.body.removeChild(script);
// if user navigates too rapidly, <style> tags can build up
2020-01-24 19:31:49 +01:00
// $FlowFixMe
2020-01-23 17:21:36 +01:00
if (document.body.getElementsByTagName('style').length) {
2020-01-24 19:31:49 +01:00
// $FlowFixMe
2020-01-23 19:44:55 +01:00
document.body.getElementsByTagName('style')[0].remove();
2020-01-23 17:21:36 +01:00
}
};
}, []);
return (
2020-01-24 19:31:49 +01:00
<div className="ads-wrapper">
2020-01-23 19:44:55 +01:00
<p>Ads</p>
2020-01-24 19:31:49 +01:00
<p>
<I18nMessage
tokens={{
sign_in_to_lbrytv: (
<Button
button="link"
label={__('Sign in to lbry.tv')}
navigate={`/$/${PAGES.AUTH}?redirect=${pathname}`}
/>
),
download_the_app: <Button button="link" label={__('download the app')} href="https://lbry.com/get" />,
}}
>
Hate these? %sign_in_to_lbrytv% or %download_the_app% for an ad free experience.
</I18nMessage>
</p>
2020-01-23 19:44:55 +01:00
<div
id="rc-widget-0a74cf"
data-rc-widget
data-widget-host="habitat"
data-endpoint="//trends.revcontent.com"
data-widget-id="117427"
/>
2020-01-24 19:31:49 +01:00
</div>
2020-01-23 17:21:36 +01:00
);
2020-01-23 19:44:55 +01:00
}
2020-01-23 17:21:36 +01:00
2020-01-24 19:31:49 +01:00
export default withRouter(Ads);