diff options
author | 2018-03-27 15:19:44 +0200 | |
---|---|---|
committer | 2018-03-27 15:19:44 +0200 | |
commit | 63d4281300ef86cbec6869bad3cbbb976c219c7d (patch) | |
tree | 29ae51983e0e7b07f0d450b6b8928a227620903a /src/stores | |
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
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.js | 6 | ||||
-rw-r--r-- | src/stores/UserStore.js | 20 |
2 files changed, 25 insertions, 1 deletions
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 | } |