2016-12-07 23:34:15 +01: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
|
|
|
|
|
2016-12-20 22:53:14 +01:00
|
|
|
module.exports = Notice
|
2016-12-07 23:34:15 +01:00
|
|
|
|
|
|
|
inherits(Notice, Component)
|
|
|
|
function Notice () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.render = function () {
|
2016-12-20 22:53:14 +01:00
|
|
|
const { notice, onConfirm } = this.props
|
|
|
|
const { title, date, body } = notice
|
2017-02-20 23:58:24 +01:00
|
|
|
const state = this.state || { disclaimerDisabled: true }
|
|
|
|
const disabled = state.disclaimerDisabled
|
2016-12-07 23:34:15 +01:00
|
|
|
|
|
|
|
return (
|
2017-08-04 01:30:57 +02:00
|
|
|
h('.flex-column.flex-center.flex-grow', {
|
|
|
|
style: {
|
2017-08-04 04:17:46 +02:00
|
|
|
width: '100%',
|
2017-08-04 01:30:57 +02:00
|
|
|
},
|
|
|
|
}, [
|
2017-02-20 21:59:31 +01:00
|
|
|
h('h3.flex-center.text-transform-uppercase.terms-header', {
|
2016-12-07 23:34:15 +01:00
|
|
|
style: {
|
|
|
|
background: '#EBEBEB',
|
|
|
|
color: '#AEAEAE',
|
|
|
|
width: '100%',
|
|
|
|
fontSize: '20px',
|
|
|
|
textAlign: 'center',
|
|
|
|
padding: 6,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
title,
|
|
|
|
]),
|
|
|
|
|
2017-02-20 21:59:31 +01:00
|
|
|
h('h5.flex-center.text-transform-uppercase.terms-header', {
|
2016-12-16 22:31:12 +01:00
|
|
|
style: {
|
|
|
|
background: '#EBEBEB',
|
|
|
|
color: '#AEAEAE',
|
|
|
|
marginBottom: 24,
|
|
|
|
width: '100%',
|
|
|
|
fontSize: '20px',
|
|
|
|
textAlign: 'center',
|
|
|
|
padding: 6,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
date,
|
|
|
|
]),
|
|
|
|
|
2016-12-07 23:34:15 +01:00
|
|
|
h('style', `
|
|
|
|
|
|
|
|
.markdown {
|
|
|
|
overflow-x: hidden;
|
|
|
|
}
|
2016-12-20 22:53:14 +01:00
|
|
|
|
2016-12-07 23:34:15 +01:00
|
|
|
.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 {
|
2016-12-16 22:40:32 +01:00
|
|
|
color: #df6b0e;
|
2016-12-07 23:34:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
`),
|
|
|
|
|
|
|
|
h('div.markdown', {
|
2017-02-20 23:58:24 +01:00
|
|
|
onScroll: (e) => {
|
|
|
|
var object = e.currentTarget
|
|
|
|
if (object.offsetHeight + object.scrollTop + 100 >= object.scrollHeight) {
|
|
|
|
this.setState({disclaimerDisabled: false})
|
|
|
|
}
|
|
|
|
},
|
2016-12-07 23:34:15 +01:00
|
|
|
style: {
|
|
|
|
background: 'rgb(235, 235, 235)',
|
|
|
|
height: '310px',
|
|
|
|
padding: '6px',
|
|
|
|
width: '90%',
|
|
|
|
overflowY: 'scroll',
|
|
|
|
scroll: 'auto',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h(ReactMarkdown, {
|
2017-03-27 22:33:04 +02:00
|
|
|
className: 'notice-box',
|
2016-12-20 22:53:14 +01:00
|
|
|
source: body,
|
2016-12-07 23:34:15 +01:00
|
|
|
skipHtml: true,
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('button', {
|
2017-02-20 23:58:24 +01:00
|
|
|
disabled,
|
2017-03-23 02:34:39 +01:00
|
|
|
onClick: () => {
|
|
|
|
this.setState({disclaimerDisabled: true})
|
|
|
|
onConfirm()
|
|
|
|
},
|
2016-12-07 23:34:15 +01:00
|
|
|
style: {
|
|
|
|
marginTop: '18px',
|
|
|
|
},
|
2017-06-09 19:48:28 +02:00
|
|
|
}, 'Accept'),
|
2016-12-07 23:34:15 +01:00
|
|
|
])
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.componentDidMount = function () {
|
|
|
|
var node = findDOMNode(this)
|
|
|
|
linker.setupListener(node)
|
2017-04-27 06:05:45 +02:00
|
|
|
if (document.getElementsByClassName('notice-box')[0].clientHeight < 310) {
|
|
|
|
this.setState({disclaimerDisabled: false})
|
|
|
|
}
|
2016-12-07 23:34:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Notice.prototype.componentWillUnmount = function () {
|
|
|
|
var node = findDOMNode(this)
|
|
|
|
linker.teardownListener(node)
|
|
|
|
}
|