diff options
author | 2018-03-27 15:19:44 +0200 | |
---|---|---|
committer | 2018-03-27 15:19:44 +0200 | |
commit | 63d4281300ef86cbec6869bad3cbbb976c219c7d (patch) | |
tree | 29ae51983e0e7b07f0d450b6b8928a227620903a | |
parent | move windows arch config to electron-builder.yml (diff) | |
download | ferdium-app-63d4281300ef86cbec6869bad3cbbb976c219c7d.tar.gz ferdium-app-63d4281300ef86cbec6869bad3cbbb976c219c7d.tar.zst ferdium-app-63d4281300ef86cbec6869bad3cbbb976c219c7d.zip |
Move "locale" to user data
-rw-r--r-- | src/containers/settings/EditSettingsScreen.js | 10 | ||||
-rw-r--r-- | src/models/User.js | 2 | ||||
-rw-r--r-- | src/stores/AppStore.js | 6 | ||||
-rw-r--r-- | src/stores/UserStore.js | 20 |
4 files changed, 28 insertions, 10 deletions
diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index 1fa7ce8bc..e67c2964b 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js | |||
@@ -91,15 +91,13 @@ export default class EditSettingsScreen extends Component { | |||
91 | showDisabledServices: settingsData.showDisabledServices, | 91 | showDisabledServices: settingsData.showDisabledServices, |
92 | showMessageBadgeWhenMuted: settingsData.showMessageBadgeWhenMuted, | 92 | showMessageBadgeWhenMuted: settingsData.showMessageBadgeWhenMuted, |
93 | enableSpellchecking: settingsData.enableSpellchecking, | 93 | enableSpellchecking: settingsData.enableSpellchecking, |
94 | // spellcheckingLanguage: settingsData.spellcheckingLanguage, | ||
95 | locale: settingsData.locale, | ||
96 | beta: settingsData.beta, | ||
97 | }, | 94 | }, |
98 | }); | 95 | }); |
99 | 96 | ||
100 | user.update({ | 97 | user.update({ |
101 | userData: { | 98 | userData: { |
102 | beta: settingsData.beta, | 99 | beta: settingsData.beta, |
100 | locale: settingsData.locale, | ||
103 | }, | 101 | }, |
104 | }); | 102 | }); |
105 | } | 103 | } |
@@ -169,12 +167,6 @@ export default class EditSettingsScreen extends Component { | |||
169 | value: settings.all.enableSpellchecking, | 167 | value: settings.all.enableSpellchecking, |
170 | default: DEFAULT_APP_SETTINGS.enableSpellchecking, | 168 | default: DEFAULT_APP_SETTINGS.enableSpellchecking, |
171 | }, | 169 | }, |
172 | // spellcheckingLanguage: { | ||
173 | // label: intl.formatMessage(messages.spellcheckingLanguage), | ||
174 | // value: settings.all.spellcheckingLanguage, | ||
175 | // options: spellcheckerLocales, | ||
176 | // default: DEFAULT_APP_SETTINGS.spellcheckingLanguage, | ||
177 | // }, | ||
178 | locale: { | 170 | locale: { |
179 | label: intl.formatMessage(messages.language), | 171 | label: intl.formatMessage(messages.language), |
180 | value: app.locale, | 172 | value: app.locale, |
diff --git a/src/models/User.js b/src/models/User.js index 2e5df4795..3e4aa187d 100644 --- a/src/models/User.js +++ b/src/models/User.js | |||
@@ -15,6 +15,7 @@ export default class User { | |||
15 | @observable donor = {}; | 15 | @observable donor = {}; |
16 | @observable isDonor = false; | 16 | @observable isDonor = false; |
17 | @observable isMiner = false; | 17 | @observable isMiner = false; |
18 | @observable locale = false; | ||
18 | 19 | ||
19 | constructor(data) { | 20 | constructor(data) { |
20 | if (!data.id) { | 21 | if (!data.id) { |
@@ -33,5 +34,6 @@ export default class User { | |||
33 | this.isDonor = data.isDonor || this.isDonor; | 34 | this.isDonor = data.isDonor || this.isDonor; |
34 | this.isSubscriptionOwner = data.isSubscriptionOwner || this.isSubscriptionOwner; | 35 | this.isSubscriptionOwner = data.isSubscriptionOwner || this.isSubscriptionOwner; |
35 | this.isMiner = data.isMiner || this.isMiner; | 36 | this.isMiner = data.isMiner || this.isMiner; |
37 | this.locale = data.locale || this.locale; | ||
36 | } | 38 | } |
37 | } | 39 | } |
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 4ac8325d4..94ed308f3 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -15,6 +15,8 @@ import { gaEvent } from '../lib/analytics'; | |||
15 | 15 | ||
16 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; | 16 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; |
17 | 17 | ||
18 | const debug = require('debug')('AppStore'); | ||
19 | |||
18 | const { app } = remote; | 20 | const { app } = remote; |
19 | 21 | ||
20 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | 22 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; |
@@ -279,13 +281,15 @@ export default class AppStore extends Store { | |||
279 | } | 281 | } |
280 | 282 | ||
281 | _setLocale() { | 283 | _setLocale() { |
282 | const locale = this.stores.settings.all.locale; | 284 | const { locale } = this.stores.user.data; |
283 | 285 | ||
284 | if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { | 286 | if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { |
285 | this.locale = locale; | 287 | this.locale = locale; |
286 | } else if (!locale) { | 288 | } else if (!locale) { |
287 | this.locale = this._getDefaultLocale(); | 289 | this.locale = this._getDefaultLocale(); |
288 | } | 290 | } |
291 | |||
292 | debug(`Set locale to "${this.locale}"`); | ||
289 | } | 293 | } |
290 | 294 | ||
291 | _getDefaultLocale() { | 295 | _getDefaultLocale() { |
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 7dbbd955b..c151f6d59 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -9,6 +9,8 @@ import Request from './lib/Request'; | |||
9 | import CachedRequest from './lib/CachedRequest'; | 9 | import CachedRequest from './lib/CachedRequest'; |
10 | import { gaEvent } from '../lib/analytics'; | 10 | import { gaEvent } from '../lib/analytics'; |
11 | 11 | ||
12 | const debug = require('debug')('UserStore'); | ||
13 | |||
12 | // TODO: split stores into UserStore and AuthStore | 14 | // TODO: split stores into UserStore and AuthStore |
13 | export default class UserStore extends Store { | 15 | export default class UserStore extends Store { |
14 | BASE_ROUTE = '/auth'; | 16 | BASE_ROUTE = '/auth'; |
@@ -69,6 +71,11 @@ export default class UserStore extends Store { | |||
69 | ]); | 71 | ]); |
70 | } | 72 | } |
71 | 73 | ||
74 | setup() { | ||
75 | // Data migration | ||
76 | this._migrateUserLocale(); | ||
77 | } | ||
78 | |||
72 | // Routes | 79 | // Routes |
73 | get loginRoute() { | 80 | get loginRoute() { |
74 | return this.LOGIN_ROUTE; | 81 | return this.LOGIN_ROUTE; |
@@ -292,4 +299,17 @@ export default class UserStore extends Store { | |||
292 | this.id = null; | 299 | this.id = null; |
293 | } | 300 | } |
294 | } | 301 | } |
302 | |||
303 | async _migrateUserLocale() { | ||
304 | await this.getUserInfoRequest._promise; | ||
305 | |||
306 | if (!this.data.locale) { | ||
307 | debug('Migrate "locale" to user data'); | ||
308 | this.actions.user.update({ | ||
309 | userData: { | ||
310 | locale: this.stores.app.locale, | ||
311 | }, | ||
312 | }); | ||
313 | } | ||
314 | } | ||
295 | } | 315 | } |