// @flow import React from 'react'; import { render } from 'react-dom'; import { Provider } from 'mobx-react'; import { BrowserRouter as Router, Switch, Route, Redirect, } from 'react-router-dom'; import Flex from 'shared/components/Flex'; import stores from 'stores'; import DocumentsStore from 'stores/DocumentsStore'; import CollectionsStore from 'stores/CollectionsStore'; import CacheStore from 'stores/CacheStore'; import globalStyles from 'shared/styles/globals'; import 'shared/styles/prism.css'; import Home from 'scenes/Home'; import Dashboard from 'scenes/Dashboard'; import Starred from 'scenes/Starred'; import Collection from 'scenes/Collection'; import Document from 'scenes/Document'; import Search from 'scenes/Search'; import SlackAuth from 'scenes/SlackAuth'; import Flatpage from 'scenes/Flatpage'; import ErrorAuth from 'scenes/ErrorAuth'; import Error404 from 'scenes/Error404'; import ErrorBoundary from 'components/ErrorBoundary'; import ScrollToTop from 'components/ScrollToTop'; import Layout from 'components/Layout'; import RouteSidebarHidden from 'components/RouteSidebarHidden'; import flatpages from 'static/flatpages'; import { matchDocumentSlug } from 'utils/routeHelpers'; let DevTools; if (__DEV__) { DevTools = require('mobx-react-devtools').default; // eslint-disable-line global-require } let authenticatedStores; type AuthProps = { children?: React.Element, }; const Auth = ({ children }: AuthProps) => { if (stores.auth.authenticated && stores.auth.team && stores.auth.user) { // Only initialize stores once. Kept in global scope // because otherwise they will get overriden on route // change if (!authenticatedStores) { // Stores for authenticated user const { user, team } = stores.auth; const cache = new CacheStore(user.id); authenticatedStores = { documents: new DocumentsStore({ ui: stores.ui, cache, }), collections: new CollectionsStore({ ui: stores.ui, teamId: team.id, cache, }), }; if (window.Bugsnag) { Bugsnag.user = { id: user.id, name: user.name, teamId: team.id, team: team.name, }; } authenticatedStores.collections.fetchAll(); } return ( {children} ); } else { return ; } }; const notFoundSearch = () => ; const Api = () => ; const DocumentNew = () => ; const RedirectDocument = ({ match }: { match: Object }) => ( ); globalStyles(); render(
{DevTools && }
, document.getElementById('root') ); window.authenticatedStores = authenticatedStores;