2017-05-12 00:23:56 +00:00
|
|
|
// @flow
|
2018-02-11 07:23:50 +00:00
|
|
|
import * as React from 'react';
|
2016-02-27 21:53:11 +00:00
|
|
|
import { render } from 'react-dom';
|
2016-06-26 06:31:22 +00:00
|
|
|
import { Provider } from 'mobx-react';
|
2017-05-17 07:11:13 +00:00
|
|
|
import {
|
|
|
|
BrowserRouter as Router,
|
|
|
|
Switch,
|
|
|
|
Route,
|
|
|
|
Redirect,
|
|
|
|
} from 'react-router-dom';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-06-26 06:31:22 +00:00
|
|
|
import stores from 'stores';
|
2017-10-27 05:42:08 +00:00
|
|
|
import globalStyles from 'shared/styles/globals';
|
2017-11-10 21:53:51 +00:00
|
|
|
import 'shared/styles/prism.css';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2016-04-29 05:25:37 +00:00
|
|
|
import Home from 'scenes/Home';
|
|
|
|
import Dashboard from 'scenes/Dashboard';
|
2017-06-26 00:21:33 +00:00
|
|
|
import Starred from 'scenes/Starred';
|
2018-02-28 06:41:12 +00:00
|
|
|
import Drafts from 'scenes/Drafts';
|
2017-05-26 19:56:10 +00:00
|
|
|
import Collection from 'scenes/Collection';
|
2017-05-18 02:36:31 +00:00
|
|
|
import Document from 'scenes/Document';
|
2016-07-18 03:59:32 +00:00
|
|
|
import Search from 'scenes/Search';
|
2017-11-27 02:09:55 +00:00
|
|
|
import Settings from 'scenes/Settings';
|
2018-05-25 06:23:05 +00:00
|
|
|
import Members from 'scenes/Settings/Members';
|
2017-11-27 02:09:55 +00:00
|
|
|
import Slack from 'scenes/Settings/Slack';
|
2018-05-23 06:01:49 +00:00
|
|
|
import Shares from 'scenes/Settings/Shares';
|
2017-11-27 02:09:55 +00:00
|
|
|
import Tokens from 'scenes/Settings/Tokens';
|
2017-02-10 03:57:35 +00:00
|
|
|
import Error404 from 'scenes/Error404';
|
2016-08-01 16:18:27 +00:00
|
|
|
|
2017-11-13 00:08:55 +00:00
|
|
|
import ErrorBoundary from 'components/ErrorBoundary';
|
2017-07-03 05:16:48 +00:00
|
|
|
import ScrollToTop from 'components/ScrollToTop';
|
2017-06-25 00:14:36 +00:00
|
|
|
import Layout from 'components/Layout';
|
2017-12-19 06:55:14 +00:00
|
|
|
import Auth from 'components/Auth';
|
2017-07-15 04:58:43 +00:00
|
|
|
import RouteSidebarHidden from 'components/RouteSidebarHidden';
|
2017-06-25 00:14:36 +00:00
|
|
|
|
2017-09-04 21:48:56 +00:00
|
|
|
import { matchDocumentSlug } from 'utils/routeHelpers';
|
|
|
|
|
2016-06-26 05:43:28 +00:00
|
|
|
let DevTools;
|
|
|
|
if (__DEV__) {
|
2016-08-03 12:00:17 +00:00
|
|
|
DevTools = require('mobx-react-devtools').default; // eslint-disable-line global-require
|
2016-06-26 05:43:28 +00:00
|
|
|
}
|
2016-06-05 21:38:14 +00:00
|
|
|
|
2017-05-17 07:11:13 +00:00
|
|
|
const notFoundSearch = () => <Search notFound />;
|
|
|
|
const DocumentNew = () => <Document newDocument />;
|
2017-07-03 18:17:29 +00:00
|
|
|
const RedirectDocument = ({ match }: { match: Object }) => (
|
2017-07-04 17:03:41 +00:00
|
|
|
<Redirect to={`/doc/${match.params.documentSlug}`} />
|
2017-07-03 18:17:29 +00:00
|
|
|
);
|
2016-06-05 01:28:14 +00:00
|
|
|
|
2017-10-27 05:42:08 +00:00
|
|
|
globalStyles();
|
|
|
|
|
2018-05-05 23:16:08 +00:00
|
|
|
const element = document.getElementById('root');
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
render(
|
|
|
|
<React.Fragment>
|
|
|
|
<ErrorBoundary>
|
|
|
|
<Provider {...stores}>
|
|
|
|
<Router>
|
|
|
|
<ScrollToTop>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/" component={Home} />
|
2018-05-17 06:52:26 +00:00
|
|
|
<Route exact path="/share/:shareId" component={Document} />
|
2018-05-05 23:16:08 +00:00
|
|
|
<Auth>
|
|
|
|
<Layout>
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/dashboard" component={Dashboard} />
|
|
|
|
<Route exact path="/starred" component={Starred} />
|
|
|
|
<Route exact path="/drafts" component={Drafts} />
|
|
|
|
<Route exact path="/settings" component={Settings} />
|
2018-05-25 06:23:05 +00:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/settings/members"
|
|
|
|
component={Members}
|
|
|
|
/>
|
2018-05-23 06:01:49 +00:00
|
|
|
<Route exact path="/settings/shares" component={Shares} />
|
2018-05-05 23:16:08 +00:00
|
|
|
<Route exact path="/settings/tokens" component={Tokens} />
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/settings/integrations/slack"
|
|
|
|
component={Slack}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path="/collections/:id"
|
|
|
|
component={Collection}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`/d/${matchDocumentSlug}`}
|
|
|
|
component={RedirectDocument}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`/doc/${matchDocumentSlug}`}
|
|
|
|
component={Document}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={`/doc/${matchDocumentSlug}/move`}
|
|
|
|
component={Document}
|
|
|
|
/>
|
|
|
|
<Route exact path="/search" component={Search} />
|
|
|
|
<Route exact path="/search/:query" component={Search} />
|
|
|
|
<Route path="/404" component={Error404} />
|
|
|
|
<RouteSidebarHidden
|
|
|
|
exact
|
|
|
|
path={`/doc/${matchDocumentSlug}/edit`}
|
|
|
|
component={Document}
|
|
|
|
/>
|
|
|
|
<RouteSidebarHidden
|
|
|
|
exact
|
|
|
|
path="/collections/:id/new"
|
|
|
|
component={DocumentNew}
|
|
|
|
/>
|
|
|
|
<Route component={notFoundSearch} />
|
|
|
|
</Switch>
|
|
|
|
</Layout>
|
|
|
|
</Auth>
|
|
|
|
</Switch>
|
|
|
|
</ScrollToTop>
|
|
|
|
</Router>
|
|
|
|
</Provider>
|
|
|
|
</ErrorBoundary>
|
|
|
|
{DevTools && <DevTools position={{ bottom: 0, right: 0 }} />}
|
|
|
|
</React.Fragment>,
|
|
|
|
element
|
|
|
|
);
|
|
|
|
}
|
2018-02-11 07:23:50 +00:00
|
|
|
|
|
|
|
window.addEventListener('load', async () => {
|
|
|
|
// installation does not use Google Analytics, or tracking is blocked on client
|
|
|
|
// no point loading the rest of the analytics bundles
|
|
|
|
if (!process.env.GOOGLE_ANALYTICS_ID || !window.ga) return;
|
|
|
|
|
2018-02-11 07:54:54 +00:00
|
|
|
// https://github.com/googleanalytics/autotrack/issues/137#issuecomment-305890099
|
|
|
|
await import('autotrack/autotrack.js');
|
2018-02-11 07:23:50 +00:00
|
|
|
|
|
|
|
window.ga('require', 'outboundLinkTracker');
|
|
|
|
window.ga('require', 'urlChangeTracker');
|
|
|
|
});
|