diff options
author | Bennett <hello@vantezzen.io> | 2020-10-04 16:27:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 15:27:26 +0100 |
commit | c9c067b286505621fbae3fc212638b45ae1c733a (patch) | |
tree | beb3001b26ec3ffc05528d11fe60033971655a7c /src/features/nightlyBuilds | |
parent | Fine-tune nightly releases scripts (diff) | |
download | ferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.tar.gz ferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.tar.zst ferdium-app-c9c067b286505621fbae3fc212638b45ae1c733a.zip |
Add setting to enable nightly releases updates (#742)
Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/features/nightlyBuilds')
-rw-r--r-- | src/features/nightlyBuilds/Component.js | 141 | ||||
-rw-r--r-- | src/features/nightlyBuilds/index.js | 45 |
2 files changed, 186 insertions, 0 deletions
diff --git a/src/features/nightlyBuilds/Component.js b/src/features/nightlyBuilds/Component.js new file mode 100644 index 000000000..b340a0a7e --- /dev/null +++ b/src/features/nightlyBuilds/Component.js | |||
@@ -0,0 +1,141 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer, inject } from 'mobx-react'; | ||
4 | import injectSheet from 'react-jss'; | ||
5 | import { defineMessages, intlShape } from 'react-intl'; | ||
6 | import { H1 } from '@meetfranz/ui'; | ||
7 | |||
8 | import Modal from '../../components/ui/Modal'; | ||
9 | import Button from '../../components/ui/Button'; | ||
10 | import { state as ModalState } from '.'; | ||
11 | import SettingsStore from '../../stores/SettingsStore'; | ||
12 | |||
13 | const messages = defineMessages({ | ||
14 | title: { | ||
15 | id: 'feature.nightlyBuilds.title', | ||
16 | defaultMessage: '!!!Nightly Builds', | ||
17 | }, | ||
18 | info: { | ||
19 | id: 'feature.nightlyBuilds.info', | ||
20 | defaultMessage: '!!!Nightly builds are highly experimental versions of Ferdi that may contain unpolished or uncompleted features. These nightly builds are mainly used by developers to test their newly developed features and how they will perform in the final build. If you don\'t know what you are doing, we suggest not activating nightly builds.', | ||
21 | }, | ||
22 | activate: { | ||
23 | id: 'feature.nightlyBuilds.activate', | ||
24 | defaultMessage: '!!!Activate', | ||
25 | }, | ||
26 | cancel: { | ||
27 | id: 'feature.nightlyBuilds.cancel', | ||
28 | defaultMessage: '!!!Cancel', | ||
29 | }, | ||
30 | }); | ||
31 | |||
32 | const styles = () => ({ | ||
33 | info: { | ||
34 | paddingTop: 20, | ||
35 | paddingBottom: 20, | ||
36 | }, | ||
37 | headline: { | ||
38 | fontSize: 20, | ||
39 | marginBottom: 20, | ||
40 | }, | ||
41 | buttonContainer: { | ||
42 | display: 'flex', | ||
43 | }, | ||
44 | button: { | ||
45 | width: '50%', | ||
46 | marginTop: 10, | ||
47 | cursor: 'pointer', | ||
48 | }, | ||
49 | activateButton: { | ||
50 | marginRight: 10, | ||
51 | background: '#c45a5a !important', | ||
52 | color: '#ffffff !important', | ||
53 | }, | ||
54 | }); | ||
55 | |||
56 | export default @injectSheet(styles) @inject('stores', 'actions') @observer class nightlyBuildsModal extends Component { | ||
57 | static contextTypes = { | ||
58 | intl: intlShape, | ||
59 | }; | ||
60 | |||
61 | close() { | ||
62 | ModalState.isModalVisible = false; | ||
63 | |||
64 | const { ui } = this.props.actions; | ||
65 | ui.openSettings({ path: 'app' }); | ||
66 | } | ||
67 | |||
68 | activate() { | ||
69 | const { settings, user } = this.props.actions; | ||
70 | |||
71 | settings.update({ | ||
72 | type: 'app', | ||
73 | data: { | ||
74 | nightly: true, | ||
75 | }, | ||
76 | }); | ||
77 | user.update({ | ||
78 | userData: { | ||
79 | nightly: true, | ||
80 | }, | ||
81 | }); | ||
82 | this.close(); | ||
83 | } | ||
84 | |||
85 | render() { | ||
86 | const { isModalVisible } = ModalState; | ||
87 | |||
88 | const { | ||
89 | classes, | ||
90 | } = this.props; | ||
91 | |||
92 | const { intl } = this.context; | ||
93 | |||
94 | return ( | ||
95 | <Modal | ||
96 | isOpen={isModalVisible} | ||
97 | shouldCloseOnOverlayClick | ||
98 | close={this.close.bind(this)} | ||
99 | > | ||
100 | <H1 className={classes.headline}> | ||
101 | {intl.formatMessage(messages.title)} | ||
102 | </H1> | ||
103 | |||
104 | <p className={classes.info}>{intl.formatMessage(messages.info)}</p> | ||
105 | |||
106 | <div className={classes.buttonContainer}> | ||
107 | <Button | ||
108 | type="button" | ||
109 | label={intl.formatMessage(messages.activate)} | ||
110 | className={`${classes.button} ${classes.activateButton}`} | ||
111 | onClick={() => this.activate()} | ||
112 | /> | ||
113 | <Button | ||
114 | type="button" | ||
115 | label={intl.formatMessage(messages.cancel)} | ||
116 | className={classes.button} | ||
117 | onClick={() => this.close()} | ||
118 | /> | ||
119 | </div> | ||
120 | </Modal> | ||
121 | ); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | nightlyBuildsModal.wrappedComponent.propTypes = { | ||
126 | stores: PropTypes.shape({ | ||
127 | settings: PropTypes.instanceOf(SettingsStore).isRequired, | ||
128 | }).isRequired, | ||
129 | actions: PropTypes.shape({ | ||
130 | settings: PropTypes.shape({ | ||
131 | update: PropTypes.func.isRequired, | ||
132 | }).isRequired, | ||
133 | user: PropTypes.shape({ | ||
134 | update: PropTypes.func.isRequired, | ||
135 | }).isRequired, | ||
136 | ui: PropTypes.shape({ | ||
137 | openSettings: PropTypes.func.isRequired, | ||
138 | }).isRequired, | ||
139 | }).isRequired, | ||
140 | classes: PropTypes.object.isRequired, | ||
141 | }; | ||
diff --git a/src/features/nightlyBuilds/index.js b/src/features/nightlyBuilds/index.js new file mode 100644 index 000000000..34fe37d4d --- /dev/null +++ b/src/features/nightlyBuilds/index.js | |||
@@ -0,0 +1,45 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | |||
3 | export { default as Component } from './Component'; | ||
4 | |||
5 | const debug = require('debug')('Ferdi:feature:nightlyBuilds'); | ||
6 | |||
7 | const defaultState = { | ||
8 | isModalVisible: false, | ||
9 | }; | ||
10 | |||
11 | export const state = observable(defaultState); | ||
12 | |||
13 | export default function initialize() { | ||
14 | debug('Initialize nightlyBuilds feature'); | ||
15 | |||
16 | function showModal() { | ||
17 | state.isModalVisible = true; | ||
18 | } | ||
19 | |||
20 | function toggleFeature() { | ||
21 | if (window.ferdi.stores.settings.app.nightly) { | ||
22 | window.ferdi.actions.settings.update({ | ||
23 | type: 'app', | ||
24 | data: { | ||
25 | nightly: false, | ||
26 | }, | ||
27 | }); | ||
28 | window.ferdi.actions.user.update({ | ||
29 | userData: { | ||
30 | nightly: false, | ||
31 | }, | ||
32 | }); | ||
33 | } else { | ||
34 | // We need to close the settings, otherwise the modal will be drawn under the settings window | ||
35 | window.ferdi.actions.ui.closeSettings(); | ||
36 | showModal(); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | window.ferdi.features.nightlyBuilds = { | ||
41 | state, | ||
42 | showModal, | ||
43 | toggleFeature, | ||
44 | }; | ||
45 | } | ||