2017-11-14 08:04:23 -08:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const ReactMarkdown = require('react-markdown')
|
|
|
|
const linker = require('extension-link-enabler')
|
|
|
|
const findDOMNode = require('react-dom').findDOMNode
|
|
|
|
|
|
|
|
module.exports = Notice
|
|
|
|
|
|
|
|
inherits(Notice, Component)
|
|
|
|
function Notice () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.render = function () {
|
|
|
|
const { notice, onConfirm } = this.props
|
2018-07-30 06:01:21 -07:00
|
|
|
const { title, body } = notice
|
2018-08-01 08:49:30 -07:00
|
|
|
const state = this.state || { disclaimerDisabled: true }
|
2017-11-14 08:04:23 -08:00
|
|
|
const disabled = state.disclaimerDisabled
|
|
|
|
|
|
|
|
return (
|
|
|
|
h('.flex-column.flex-center.flex-grow', {
|
|
|
|
style: {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
}, [
|
2018-08-01 08:49:30 -07:00
|
|
|
h('h3.flex-center.terms-header.section-title', {
|
2017-11-14 08:04:23 -08:00
|
|
|
style: {
|
2018-07-26 17:16:24 -07:00
|
|
|
background: '#ffffff',
|
|
|
|
color: '#333333',
|
2017-11-14 08:04:23 -08:00
|
|
|
width: '100%',
|
2018-07-26 17:16:24 -07:00
|
|
|
fontSize: '16px',
|
2017-11-14 08:04:23 -08:00
|
|
|
textAlign: 'center',
|
|
|
|
padding: 6,
|
|
|
|
marginBottom: 24,
|
|
|
|
},
|
|
|
|
}, [
|
2018-07-26 11:15:51 -07:00
|
|
|
title,
|
2017-11-14 08:04:23 -08:00
|
|
|
]),
|
|
|
|
|
|
|
|
h('style', `
|
|
|
|
|
|
|
|
.markdown {
|
|
|
|
overflow-x: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.markdown h1, .markdown h2, .markdown h3 {
|
|
|
|
margin: 10px 0;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.markdown strong {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
.markdown em {
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
|
|
|
|
.markdown p {
|
|
|
|
margin: 10px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.markdown a {
|
2018-07-26 11:15:51 -07:00
|
|
|
color: #8fdc97;
|
2017-11-14 08:04:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
`),
|
|
|
|
|
|
|
|
h('div.markdown', {
|
|
|
|
onScroll: (e) => {
|
|
|
|
var object = e.currentTarget
|
|
|
|
if (object.offsetHeight + object.scrollTop + 100 >= object.scrollHeight) {
|
|
|
|
this.setState({disclaimerDisabled: false})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
style: {
|
2018-07-26 17:16:24 -07:00
|
|
|
background: '#ffffff',
|
2017-11-14 08:04:23 -08:00
|
|
|
height: '310px',
|
|
|
|
padding: '6px',
|
|
|
|
width: '90%',
|
|
|
|
overflowY: 'scroll',
|
|
|
|
scroll: 'auto',
|
2018-07-26 17:16:24 -07:00
|
|
|
borderRadius: '3px',
|
2017-11-14 08:04:23 -08:00
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(ReactMarkdown, {
|
|
|
|
className: 'notice-box',
|
|
|
|
source: body,
|
|
|
|
skipHtml: true,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('button', {
|
|
|
|
disabled,
|
|
|
|
onClick: () => {
|
2018-08-01 08:49:30 -07:00
|
|
|
this.setState({disclaimerDisabled: true})
|
2017-11-14 08:04:23 -08:00
|
|
|
onConfirm()
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
marginTop: '18px',
|
|
|
|
},
|
|
|
|
}, 'Accept'),
|
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.componentDidMount = function () {
|
|
|
|
// eslint-disable-next-line react/no-find-dom-node
|
|
|
|
var node = findDOMNode(this)
|
|
|
|
linker.setupListener(node)
|
|
|
|
if (document.getElementsByClassName('notice-box')[0].clientHeight < 310) {
|
|
|
|
this.setState({disclaimerDisabled: false})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.componentWillUnmount = function () {
|
|
|
|
// eslint-disable-next-line react/no-find-dom-node
|
|
|
|
var node = findDOMNode(this)
|
|
|
|
linker.teardownListener(node)
|
|
|
|
}
|