Implement configuration fetching during runtime
[arvados-workbench2.git] / src / index.tsx
index bc9f903d288765b70470fba499b416902df07204..102249672271bb1c7bd3652a1739f90b91287ee6 100644 (file)
@@ -15,40 +15,38 @@ import ApiToken from "./views-components/api-token/api-token";
 import authActions from "./store/auth/auth-action";
 import { authService } from "./services/services";
 import { getProjectList } from "./store/project/project-action";
+import { MuiThemeProvider } from '@material-ui/core/styles';
+import { CustomTheme } from './common/custom-theme';
+import { fetchConfig } from './common/config';
+import { setBaseUrl } from './common/api/server-api';
+
+fetchConfig()
+    .then(config => {
+
+        setBaseUrl(config.API_HOST);
+
+        const history = createBrowserHistory();
+        const store = configureStore(history);
+
+        store.dispatch(authActions.INIT());
+        store.dispatch<any>(getProjectList(authService.getUuid()));
+
+        const App = () =>
+            <MuiThemeProvider theme={CustomTheme}>
+                <Provider store={store}>
+                    <ConnectedRouter history={history}>
+                        <div>
+                            <Route path="/" component={Workbench} />
+                            <Route path="/token" component={ApiToken} />
+                        </div>
+                    </ConnectedRouter>
+                </Provider>
+            </MuiThemeProvider>;
+
+        ReactDOM.render(
+            <App />,
+            document.getElementById('root') as HTMLElement
+        );
+    });
+
 
-const history = createBrowserHistory();
-
-const store = configureStore({
-    projects: {
-        items: [],
-        currentItemId: ""
-    },
-    collections: [
-    ],
-    router: {
-        location: null
-    },
-    auth: {
-        user: undefined
-    },
-    sidePanel: []
-}, history);
-
-store.dispatch(authActions.INIT());
-const rootUuid = authService.getRootUuid();
-store.dispatch<any>(getProjectList(rootUuid));
-
-const App = () =>
-    <Provider store={store}>
-        <ConnectedRouter history={history}>
-            <div>
-                <Route path="/" component={Workbench}/>
-                <Route path="/token" component={ApiToken}/>
-            </div>
-        </ConnectedRouter>
-    </Provider>;
-
-ReactDOM.render(
-    <App/>,
-    document.getElementById('root') as HTMLElement
-);