aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/settings/EditSettingsScreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/settings/EditSettingsScreen.js')
-rw-r--r--src/containers/settings/EditSettingsScreen.js167
1 files changed, 167 insertions, 0 deletions
diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js
new file mode 100644
index 000000000..0e17cafce
--- /dev/null
+++ b/src/containers/settings/EditSettingsScreen.js
@@ -0,0 +1,167 @@
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import { inject, observer } from 'mobx-react';
4import { defineMessages, intlShape } from 'react-intl';
5
6import AppStore from '../../stores/AppStore';
7import SettingsStore from '../../stores/SettingsStore';
8import UserStore from '../../stores/UserStore';
9import Form from '../../lib/Form';
10import languages from '../../i18n/languages';
11import { gaPage } from '../../lib/analytics';
12
13
14import EditSettingsForm from '../../components/settings/settings/EditSettingsForm';
15
16const messages = defineMessages({
17 autoLaunchOnStart: {
18 id: 'settings.app.form.autoLaunchOnStart',
19 defaultMessage: '!!!Launch Franz on start',
20 },
21 autoLaunchInBackground: {
22 id: 'settings.app.form.autoLaunchInBackground',
23 defaultMessage: '!!!Open in background',
24 },
25 runInBackground: {
26 id: 'settings.app.form.runInBackground',
27 defaultMessage: '!!!Keep Franz in background when closing the window',
28 },
29 minimizeToSystemTray: {
30 id: 'settings.app.form.minimizeToSystemTray',
31 defaultMessage: '!!!Minimize Franz to system tray',
32 },
33 language: {
34 id: 'settings.app.form.language',
35 defaultMessage: '!!!Language',
36 },
37 beta: {
38 id: 'settings.app.form.beta',
39 defaultMessage: '!!!Include beta versions',
40 },
41});
42
43@inject('stores', 'actions') @observer
44export default class EditSettingsScreen extends Component {
45 static contextTypes = {
46 intl: intlShape,
47 };
48
49 componentDidMount() {
50 gaPage('Settings/App');
51 }
52
53 onSubmit(settingsData) {
54 const { app, settings, user } = this.props.actions;
55
56 app.launchOnStartup({
57 enable: settingsData.autoLaunchOnStart,
58 openInBackground: settingsData.autoLaunchInBackground,
59 });
60
61 settings.update({
62 settings: {
63 runInBackground: settingsData.runInBackground,
64 minimizeToSystemTray: settingsData.minimizeToSystemTray,
65 locale: settingsData.locale,
66 beta: settingsData.beta,
67 },
68 });
69
70 user.update({
71 userData: {
72 beta: settingsData.beta,
73 },
74 });
75 }
76
77 prepareForm() {
78 const { app, settings, user } = this.props.stores;
79 const { intl } = this.context;
80
81 const options = [];
82 Object.keys(languages).forEach((key) => {
83 options.push({
84 value: key,
85 label: languages[key],
86 });
87 });
88
89 const config = {
90 fields: {
91 autoLaunchOnStart: {
92 label: intl.formatMessage(messages.autoLaunchOnStart),
93 value: app.autoLaunchOnStart,
94 default: true,
95 },
96 autoLaunchInBackground: {
97 label: intl.formatMessage(messages.autoLaunchInBackground),
98 value: app.launchInBackground,
99 default: false,
100 },
101 runInBackground: {
102 label: intl.formatMessage(messages.runInBackground),
103 value: settings.all.runInBackground,
104 default: true,
105 },
106 minimizeToSystemTray: {
107 label: intl.formatMessage(messages.minimizeToSystemTray),
108 value: settings.all.minimizeToSystemTray,
109 default: false,
110 },
111 locale: {
112 label: intl.formatMessage(messages.language),
113 value: app.locale,
114 options,
115 default: 'en-US',
116 },
117 beta: {
118 label: intl.formatMessage(messages.beta),
119 value: user.data.beta,
120 default: false,
121 },
122 },
123 };
124
125 return new Form(config);
126 }
127
128 render() {
129 const { updateStatus, updateStatusTypes } = this.props.stores.app;
130 const { checkForUpdates, installUpdate } = this.props.actions.app;
131 const form = this.prepareForm();
132
133 return (
134 <EditSettingsForm
135 form={form}
136 checkForUpdates={checkForUpdates}
137 installUpdate={installUpdate}
138 isCheckingForUpdates={updateStatus === updateStatusTypes.CHECKING}
139 isUpdateAvailable={updateStatus === updateStatusTypes.AVAILABLE}
140 noUpdateAvailable={updateStatus === updateStatusTypes.NOT_AVAILABLE}
141 updateIsReadyToInstall={updateStatus === updateStatusTypes.DOWNLOADED}
142 onSubmit={d => this.onSubmit(d)}
143 />
144 );
145 }
146}
147
148EditSettingsScreen.wrappedComponent.propTypes = {
149 stores: PropTypes.shape({
150 app: PropTypes.instanceOf(AppStore).isRequired,
151 user: PropTypes.instanceOf(UserStore).isRequired,
152 settings: PropTypes.instanceOf(SettingsStore).isRequired,
153 }).isRequired,
154 actions: PropTypes.shape({
155 app: PropTypes.shape({
156 launchOnStartup: PropTypes.func.isRequired,
157 checkForUpdates: PropTypes.func.isRequired,
158 installUpdate: PropTypes.func.isRequired,
159 }).isRequired,
160 settings: PropTypes.shape({
161 update: PropTypes.func.isRequired,
162 }).isRequired,
163 user: PropTypes.shape({
164 update: PropTypes.func.isRequired,
165 }).isRequired,
166 }).isRequired,
167};