From a6c97490b3c6b7bca00d16bc436abf902ee7b101 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 25 Jan 2016 10:40:29 -0500 Subject: Changed first preference load to be done synchronously --- web/react/pages/channel.jsx | 17 +++-------------- web/react/stores/preference_store.jsx | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 23 deletions(-) (limited to 'web/react') diff --git a/web/react/pages/channel.jsx b/web/react/pages/channel.jsx index 1e28dab8b..5bb0294fd 100644 --- a/web/react/pages/channel.jsx +++ b/web/react/pages/channel.jsx @@ -20,12 +20,8 @@ import InviteMemberModal from '../components/invite_member_modal.jsx'; import PreferenceStore from '../stores/preference_store.jsx'; -import * as Utils from '../utils/utils.jsx'; -import * as AsyncClient from '../utils/async_client.jsx'; import * as EventHelpers from '../dispatcher/event_helpers.jsx'; -import Constants from '../utils/constants.jsx'; - var IntlProvider = ReactIntl.IntlProvider; class Root extends React.Component { @@ -92,24 +88,17 @@ class Root extends React.Component { } } -function onPreferenceChange() { - const selectedFont = PreferenceStore.get(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'selected_font', Constants.DEFAULT_FONT); - Utils.applyFont(selectedFont); - PreferenceStore.removeChangeListener(onPreferenceChange); -} - -global.window.setup_channel_page = function setup(props, team, channel) { +global.window.setup_channel_page = function setup(props, team, channel, preferences) { if (props.PostId === '') { EventHelpers.emitChannelClickEvent(channel); } else { EventHelpers.emitPostFocusEvent(props.PostId); } - PreferenceStore.addChangeListener(onPreferenceChange); - AsyncClient.getAllPreferences(); + PreferenceStore.setPreferences(preferences); ReactDOM.render( , document.getElementById('channel_view') ); -}; \ No newline at end of file +}; diff --git a/web/react/stores/preference_store.jsx b/web/react/stores/preference_store.jsx index 79eab4fe1..7ecaf0a95 100644 --- a/web/react/stores/preference_store.jsx +++ b/web/react/stores/preference_store.jsx @@ -133,6 +133,16 @@ class PreferenceStoreClass extends EventEmitter { return preference; } + setPreferences(newPreferences) { + const preferences = this.getAllPreferences(); + + for (const preference of newPreferences) { + preferences.set(getPreferenceKeyForModel(preference), preference); + } + + this.setAllPreferences(preferences); + } + emitChange() { this.emit(CHANGE_EVENT); } @@ -155,18 +165,11 @@ class PreferenceStoreClass extends EventEmitter { this.emitChange(); break; } - case ActionTypes.RECIEVED_PREFERENCES: { - const preferences = this.getAllPreferences(); - - for (const preference of action.preferences) { - preferences.set(getPreferenceKeyForModel(preference), preference); - } - - this.setAllPreferences(preferences); + case ActionTypes.RECIEVED_PREFERENCES: + this.setPreferences(action.preferences); this.emitChange(); break; } - } } } -- cgit v1.2.3-1-g7c22