From 63d4281300ef86cbec6869bad3cbbb976c219c7d Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Tue, 27 Mar 2018 15:19:44 +0200 Subject: Move "locale" to user data --- src/containers/settings/EditSettingsScreen.js | 10 +--------- src/models/User.js | 2 ++ src/stores/AppStore.js | 6 +++++- src/stores/UserStore.js | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') 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 { showDisabledServices: settingsData.showDisabledServices, showMessageBadgeWhenMuted: settingsData.showMessageBadgeWhenMuted, enableSpellchecking: settingsData.enableSpellchecking, - // spellcheckingLanguage: settingsData.spellcheckingLanguage, - locale: settingsData.locale, - beta: settingsData.beta, }, }); user.update({ userData: { beta: settingsData.beta, + locale: settingsData.locale, }, }); } @@ -169,12 +167,6 @@ export default class EditSettingsScreen extends Component { value: settings.all.enableSpellchecking, default: DEFAULT_APP_SETTINGS.enableSpellchecking, }, - // spellcheckingLanguage: { - // label: intl.formatMessage(messages.spellcheckingLanguage), - // value: settings.all.spellcheckingLanguage, - // options: spellcheckerLocales, - // default: DEFAULT_APP_SETTINGS.spellcheckingLanguage, - // }, locale: { label: intl.formatMessage(messages.language), 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 { @observable donor = {}; @observable isDonor = false; @observable isMiner = false; + @observable locale = false; constructor(data) { if (!data.id) { @@ -33,5 +34,6 @@ export default class User { this.isDonor = data.isDonor || this.isDonor; this.isSubscriptionOwner = data.isSubscriptionOwner || this.isSubscriptionOwner; this.isMiner = data.isMiner || this.isMiner; + this.locale = data.locale || this.locale; } } 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'; import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; +const debug = require('debug')('AppStore'); + const { app } = remote; const defaultLocale = DEFAULT_APP_SETTINGS.locale; @@ -279,13 +281,15 @@ export default class AppStore extends Store { } _setLocale() { - const locale = this.stores.settings.all.locale; + const { locale } = this.stores.user.data; if (locale && Object.prototype.hasOwnProperty.call(locales, locale) && locale !== this.locale) { this.locale = locale; } else if (!locale) { this.locale = this._getDefaultLocale(); } + + debug(`Set locale to "${this.locale}"`); } _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'; import CachedRequest from './lib/CachedRequest'; import { gaEvent } from '../lib/analytics'; +const debug = require('debug')('UserStore'); + // TODO: split stores into UserStore and AuthStore export default class UserStore extends Store { BASE_ROUTE = '/auth'; @@ -69,6 +71,11 @@ export default class UserStore extends Store { ]); } + setup() { + // Data migration + this._migrateUserLocale(); + } + // Routes get loginRoute() { return this.LOGIN_ROUTE; @@ -292,4 +299,17 @@ export default class UserStore extends Store { this.id = null; } } + + async _migrateUserLocale() { + await this.getUserInfoRequest._promise; + + if (!this.data.locale) { + debug('Migrate "locale" to user data'); + this.actions.user.update({ + userData: { + locale: this.stores.app.locale, + }, + }); + } + } } -- cgit v1.2.3-54-g00ecf