This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/frontend/index.js

157 lines
4.7 KiB
JavaScript
Raw Normal View History

2017-05-12 00:23:56 +00:00
// @flow
2016-02-27 21:53:11 +00:00
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'mobx-react';
2017-05-17 07:11:13 +00:00
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
} from 'react-router-dom';
import Flex from 'components/Flex';
2016-02-27 21:53:11 +00:00
import stores from 'stores';
2017-06-28 04:20:09 +00:00
import DocumentsStore from 'stores/DocumentsStore';
import CollectionsStore from 'stores/CollectionsStore';
2017-07-16 18:47:48 +00:00
import CacheStore from 'stores/CacheStore';
2016-02-27 21:53:11 +00:00
import 'normalize.css/normalize.css';
2017-09-10 20:27:15 +00:00
import 'styles/base.css';
2016-07-15 06:03:04 +00:00
import 'styles/fonts.css';
2017-09-10 20:27:15 +00:00
import 'styles/transitions.css';
import 'styles/prism-tomorrow.css';
import 'styles/hljs-github-gist.css';
2016-04-29 05:25:37 +00:00
import Home from 'scenes/Home';
import Dashboard from 'scenes/Dashboard';
import Starred from 'scenes/Starred';
import Collection from 'scenes/Collection';
Slate editor (#38) * WIP: Slate editor * WIP * Focus at start / end working * ah ha * Super basic floating toolbar * Nested list editing * Pulling more logic into plugins * inline code markdown * Backspace at end of code block should remove mark * Ensure there is always an empty line at editor end * Add keyboard shortcuts for bold, italic, underline * Add strikethrough shortcode and toolbar * Toolbar to declarative Fixed paragraph styling Removed unused stuffs * Super basic link editing * Split Toolbar, now possible to edit and remove links * Add new link to selection from toolbar working * Ensure toolbar doesn't extend off screen * Fix minor js issues, disable formatting of document title * Boom, icons * Remove codemirror, fix MD parsing issues * CMD+S now saves inplace * Add --- shortcut for horizontal rule * Improved styling for link editor * Add header anchors in readOnly * More readable core text color * Restored image file uploading :tada: * Add support for inline md syntax, ** __ etc * Centered * Flooooow * Checklist support * Upgrade edit list plugin * Finally. Allow keydown within rich textarea * Update Markdown serializer * Cleanup, remove async editor loading * Editor > MarkdownEditor Fixed unsaved changes warning triggered when all changes are saved * MOAR typing * Combine edit and view * Fixed checkboxes still editable in readOnly * wip * Breadcrumb Restored scroll * Move document scene actions to menu * Added: Support for code blocks, syntax highlighting * Cleanup * > styled component * Prevent CMD+Enter from adding linebreak * Show image uploading in layout activity indicator * Upgrade editor deps * Improve link toolbar. Only one scenario where it's not working now
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';
2016-04-29 05:25:37 +00:00
import SlackAuth from 'scenes/SlackAuth';
2016-09-15 03:50:59 +00:00
import Flatpage from 'scenes/Flatpage';
2016-08-28 17:59:34 +00:00
import ErrorAuth from 'scenes/ErrorAuth';
2017-02-10 03:57:35 +00:00
import Error404 from 'scenes/Error404';
2016-08-01 16:18:27 +00:00
2017-07-03 05:16:48 +00:00
import ScrollToTop from 'components/ScrollToTop';
import Layout from 'components/Layout';
import RouteSidebarHidden from 'components/RouteSidebarHidden';
2016-09-15 03:50:59 +00:00
import flatpages from 'static/flatpages';
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
let authenticatedStores;
2017-05-17 07:11:13 +00:00
type AuthProps = {
children?: React.Element<any>,
};
const Auth = ({ children }: AuthProps) => {
2017-09-03 22:45:25 +00:00
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
2017-09-03 22:45:25 +00:00
const { user, team } = stores.auth;
const cache = new CacheStore(user.id);
authenticatedStores = {
2017-07-16 18:47:48 +00:00
documents: new DocumentsStore({
ui: stores.ui,
2017-07-16 18:47:48 +00:00
cache,
}),
collections: new CollectionsStore({
ui: stores.ui,
2017-09-03 22:45:25 +00:00
teamId: team.id,
2017-07-16 18:47:48 +00:00
cache,
}),
};
2017-06-28 04:20:09 +00:00
authenticatedStores.collections.fetchAll();
}
return (
<Flex auto>
<Provider {...authenticatedStores}>
{children}
</Provider>
</Flex>
);
2017-05-17 07:11:13 +00:00
} else {
return <Redirect to="/" />;
2016-02-27 21:53:11 +00:00
}
2017-05-17 07:11:13 +00:00
};
const notFoundSearch = () => <Search notFound />;
const Api = () => <Flatpage title="API" content={flatpages.api} />;
const DocumentNew = () => <Document newDocument />;
2017-07-03 18:17:29 +00:00
const RedirectDocument = ({ match }: { match: Object }) => (
<Redirect to={`/doc/${match.params.documentSlug}`} />
2017-07-03 18:17:29 +00:00
);
2016-06-05 01:28:14 +00:00
const matchDocumentSlug = ':documentSlug([0-9a-zA-Z-]*-[a-zA-z0-9]{10,15})';
render(
<div style={{ display: 'flex', flex: 1, height: '100%' }}>
<Provider {...stores}>
2017-05-17 07:11:13 +00:00
<Router>
2017-07-03 05:16:48 +00:00
<ScrollToTop>
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/auth/slack" component={SlackAuth} />
<Route exact path="/auth/slack/commands" component={SlackAuth} />
<Route exact path="/auth/error" component={ErrorAuth} />
<Auth>
<Layout>
<Switch>
<Route exact path="/dashboard" component={Dashboard} />
<Route exact path="/starred" component={Starred} />
<Route exact path="/collections/:id" component={Collection} />
2017-07-03 18:17:29 +00:00
<Route
exact
path={`/d/${matchDocumentSlug}`}
2017-07-03 18:17:29 +00:00
component={RedirectDocument}
/>
<Route
exact
path={`/doc/${matchDocumentSlug}`}
2017-07-03 18:17:29 +00:00
component={Document}
/>
<Route exact path="/search" component={Search} />
<Route exact path="/search/:query" component={Search} />
2017-07-16 22:14:15 +00:00
<Route exact path="/developers" component={Api} />
<Route path="/404" component={Error404} />
<RouteSidebarHidden
exact
path={`/doc/${matchDocumentSlug}/:edit`}
component={Document}
/>
<RouteSidebarHidden
exact
path="/collections/:id/new"
component={DocumentNew}
/>
2017-07-03 05:16:48 +00:00
<Route component={notFoundSearch} />
</Switch>
</Layout>
</Auth>
</Switch>
</ScrollToTop>
2017-04-29 21:14:11 +00:00
</Router>
</Provider>
2017-05-12 00:23:56 +00:00
{DevTools && <DevTools position={{ bottom: 0, right: 0 }} />}
</div>,
document.getElementById('root')
);
2017-06-28 04:20:09 +00:00
window.authenticatedStores = authenticatedStores;