diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
commit | 975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165 (patch) | |
tree | a0852f9faf6de9962b5478ed3f1bbaccd71062c0 /web/react/components/center_panel.jsx | |
parent | 160e1a8bea6d8280ef3b41a4a9f80674b75f3eb0 (diff) | |
parent | d7cdcf082fab6c0cb7c2fe4bed821bd1a8000e69 (diff) | |
download | chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.gz chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.bz2 chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.zip |
Merge pull request #2331 from mattermost/plt-1680
PLT-1680 Converting client to react-router. Stage 1
Diffstat (limited to 'web/react/components/center_panel.jsx')
-rw-r--r-- | web/react/components/center_panel.jsx | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/web/react/components/center_panel.jsx b/web/react/components/center_panel.jsx index 2422588cf..2ea840c1e 100644 --- a/web/react/components/center_panel.jsx +++ b/web/react/components/center_panel.jsx @@ -25,40 +25,43 @@ export default class CenterPanel extends React.Component { constructor(props) { super(props); - this.onPreferenceChange = this.onPreferenceChange.bind(this); - this.onChannelChange = this.onChannelChange.bind(this); - this.onUserChange = this.onUserChange.bind(this); + this.getStateFromStores = this.getStateFromStores.bind(this); + this.validState = this.validState.bind(this); + this.onStoresChange = this.onStoresChange.bind(this); + this.state = this.getStateFromStores(); + } + getStateFromStores() { const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999); - this.state = { - showTutorialScreens: tutorialStep === TutorialSteps.INTRO_SCREENS, + return { + showTutorialScreens: tutorialStep <= TutorialSteps.INTRO_SCREENS, showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS, user: UserStore.getCurrentUser(), + channel: ChannelStore.getCurrent(), profiles: JSON.parse(JSON.stringify(UserStore.getProfiles())) }; } - componentDidMount() { - PreferenceStore.addChangeListener(this.onPreferenceChange); - ChannelStore.addChangeListener(this.onChannelChange); - UserStore.addChangeListener(this.onUserChange); - } - componentWillUnmount() { - PreferenceStore.removeChangeListener(this.onPreferenceChange); - ChannelStore.removeChangeListener(this.onChannelChange); - UserStore.removeChangeListener(this.onUserChange); + validState() { + return this.state.user && this.state.channel && this.state.profiles; } - onPreferenceChange() { - const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999); - this.setState({showTutorialScreens: tutorialStep <= TutorialSteps.INTRO_SCREENS}); + onStoresChange() { + this.setState(this.getStateFromStores()); } - onChannelChange() { - this.setState({showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS}); + componentDidMount() { + PreferenceStore.addChangeListener(this.onStoresChange); + ChannelStore.addChangeListener(this.onStoresChange); + UserStore.addChangeListener(this.onStoresChange); } - onUserChange() { - this.setState({user: UserStore.getCurrentUser(), profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))}); + componentWillUnmount() { + PreferenceStore.removeChangeListener(this.onStoresChange); + ChannelStore.removeChangeListener(this.onStoresChange); + UserStore.removeChangeListener(this.onStoresChange); } render() { - const channel = ChannelStore.getCurrent(); + if (!this.validState()) { + return null; + } + const channel = this.state.channel; var handleClick = null; let postsContainer; let createPost; |