diff options
Diffstat (limited to 'src/features/delayApp/Component.js')
-rw-r--r-- | src/features/delayApp/Component.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/features/delayApp/Component.js b/src/features/delayApp/Component.js new file mode 100644 index 000000000..403340c7b --- /dev/null +++ b/src/features/delayApp/Component.js | |||
@@ -0,0 +1,88 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | import injectSheet from 'react-jss'; | ||
6 | |||
7 | import Button from '../../components/ui/Button'; | ||
8 | |||
9 | import { config } from './'; | ||
10 | import styles from './styles'; | ||
11 | |||
12 | const messages = defineMessages({ | ||
13 | headline: { | ||
14 | id: 'feature.delayApp.headline', | ||
15 | defaultMessage: '!!!Please purchase license to skip waiting', | ||
16 | }, | ||
17 | action: { | ||
18 | id: 'feature.delayApp.action', | ||
19 | defaultMessage: '!!!Get a Franz Supporter License', | ||
20 | }, | ||
21 | text: { | ||
22 | id: 'feature.delayApp.text', | ||
23 | defaultMessage: '!!!Franz will continue in {seconds} seconds.', | ||
24 | }, | ||
25 | }); | ||
26 | |||
27 | export default @inject('actions') @injectSheet(styles) @observer class DelayApp extends Component { | ||
28 | static propTypes = { | ||
29 | // eslint-disable-next-line | ||
30 | classes: PropTypes.object.isRequired, | ||
31 | }; | ||
32 | |||
33 | static contextTypes = { | ||
34 | intl: intlShape, | ||
35 | }; | ||
36 | |||
37 | state = { | ||
38 | countdown: config.delayDuration, | ||
39 | } | ||
40 | |||
41 | componentDidMount() { | ||
42 | this.countdownInterval = setInterval(() => { | ||
43 | this.setState({ | ||
44 | countdown: this.state.countdown - this.countdownIntervalTimeout, | ||
45 | }); | ||
46 | |||
47 | if (this.state.countdown <= 0) { | ||
48 | // reload(); | ||
49 | clearInterval(this.countdownInterval); | ||
50 | } | ||
51 | }, this.countdownIntervalTimeout); | ||
52 | } | ||
53 | |||
54 | componentWillUnmount() { | ||
55 | clearInterval(this.countdownInterval); | ||
56 | } | ||
57 | |||
58 | countdownInterval = null; | ||
59 | countdownIntervalTimeout = 1000; | ||
60 | |||
61 | render() { | ||
62 | const { classes, actions } = this.props; | ||
63 | const { intl } = this.context; | ||
64 | |||
65 | return ( | ||
66 | <div className={`${classes.container}`}> | ||
67 | <h1 className={classes.headline}>{intl.formatMessage(messages.headline)}</h1> | ||
68 | <Button | ||
69 | label={intl.formatMessage(messages.action)} | ||
70 | className={classes.button} | ||
71 | buttonType="inverted" | ||
72 | onClick={() => actions.ui.openSettings({ path: 'user' })} | ||
73 | /> | ||
74 | <p className="footnote">{intl.formatMessage(messages.text, { | ||
75 | seconds: this.state.countdown / 1000, | ||
76 | })}</p> | ||
77 | </div> | ||
78 | ); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | DelayApp.wrappedComponent.propTypes = { | ||
83 | actions: PropTypes.shape({ | ||
84 | ui: PropTypes.shape({ | ||
85 | openSettings: PropTypes.func.isRequired, | ||
86 | }).isRequired, | ||
87 | }).isRequired, | ||
88 | }; | ||