From 6c4c706313eb765eb00c639f381646be74f27b69 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Tue, 25 Apr 2017 11:46:02 -0400
Subject: Start moving webapp to Redux (#6140)

* Start moving webapp to Redux

* Fix localforage import

* Updates per feedback

* Feedback udpates and a few fixes

* Minor updates

* Fix statuses, config not loading properly, getMe sanitizing too much

* Fix preferences

* Fix user autocomplete

* Fix sessions and audits

* Fix error handling for all redux actions

* Use new directory structure for components and containers

* Refresh immediately on logout instead of after timeout

* Add fetch polyfill
---
 webapp/root.jsx | 43 +++++++++++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 10 deletions(-)

(limited to 'webapp/root.jsx')

diff --git a/webapp/root.jsx b/webapp/root.jsx
index 177eb1ec4..b2da6a54c 100644
--- a/webapp/root.jsx
+++ b/webapp/root.jsx
@@ -6,22 +6,28 @@ require('perfect-scrollbar/jquery')($);
 
 import React from 'react';
 import ReactDOM from 'react-dom';
+import {Provider} from 'react-redux';
 import {Router, browserHistory} from 'react-router/es6';
 import PDFJS from 'pdfjs-dist';
-import * as GlobalActions from 'actions/global_actions.jsx';
+
 import * as Websockets from 'actions/websocket_actions.jsx';
+import {loadMeAndConfig} from 'actions/user_actions.jsx';
 import BrowserStore from 'stores/browser_store.jsx';
 import ChannelStore from 'stores/channel_store.jsx';
 import UserStore from 'stores/user_store.jsx';
 import * as I18n from 'i18n/i18n.jsx';
 import * as AsyncClient from 'utils/async_client.jsx';
 
+import {getClientConfig, getLicenseConfig, setUrl} from 'mattermost-redux/actions/general';
+
 // Import our styles
 import 'bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css';
 import 'google-fonts/google-fonts.css';
 import 'sass/styles.scss';
 import 'katex/dist/katex.min.css';
 
+import store from 'stores/redux_store.jsx';
+
 // Import the root of our routing tree
 import rRoot from 'routes/route_root.jsx';
 
@@ -51,11 +57,26 @@ function preRenderSetup(callwhendone) {
 
     var d1 = $.Deferred(); //eslint-disable-line new-cap
 
-    GlobalActions.emitInitialLoad(
-        () => {
-            d1.resolve();
-        }
-    );
+    setUrl(window.location.origin);
+
+    const currentUserId = localStorage.getItem('currentUserId');
+
+    if (currentUserId) {
+        loadMeAndConfig(() => d1.resolve());
+    } else {
+        getClientConfig()(store.dispatch, store.getState).then(
+            (config) => {
+                global.window.mm_config = config;
+
+                getLicenseConfig()(store.dispatch, store.getState).then(
+                    (license) => {
+                        global.window.mm_license = license;
+                        d1.resolve();
+                    }
+                );
+            }
+        );
+    }
 
     // Make sure the websockets close and reset version
     $(window).on('beforeunload',
@@ -86,10 +107,12 @@ function preRenderSetup(callwhendone) {
 
 function renderRootComponent() {
     ReactDOM.render((
-        <Router
-            history={browserHistory}
-            routes={rRoot}
-        />
+        <Provider store={store}>
+            <Router
+                history={browserHistory}
+                routes={rRoot}
+            />
+        </Provider>
     ),
     document.getElementById('root'));
 }
-- 
cgit v1.2.3-1-g7c22

