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

129 lines
3.8 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 'reflexbox';
2016-02-27 21:53:11 +00:00
import stores from 'stores';
import CollectionsStore from 'stores/CollectionsStore';
2016-02-27 21:53:11 +00:00
import 'normalize.css/normalize.css';
2016-07-15 06:03:04 +00:00
import 'styles/base.scss';
import 'styles/fonts.css';
2016-10-09 22:17:22 +00:00
import 'styles/transitions.scss';
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 'styles/prism-tomorrow.scss';
2016-07-15 06:03:04 +00:00
import 'styles/hljs-github-gist.scss';
2016-04-29 05:25:37 +00:00
import Home from 'scenes/Home';
import Dashboard from 'scenes/Dashboard';
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-08-24 03:39:31 +00:00
import Settings from 'scenes/Settings';
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
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) => {
if (stores.user.authenticated && stores.user.team) {
// Only initialize stores once. Kept in global scope
// because otherwise they will get overriden on route
// change
if (!authenticatedStores) {
// Stores for authenticated user
authenticatedStores = {
collections: new CollectionsStore({
teamId: stores.user.team.id,
}),
};
authenticatedStores.collections.fetch();
}
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 KeyboardShortcuts = () => (
<Flatpage title="Keyboard shortcuts" content={flatpages.keyboard} />
);
const Api = () => <Flatpage title="API" content={flatpages.api} />;
const DocumentNew = () => <Document newDocument />;
const DocumentNewChild = () => <Document newChildDocument />;
2016-06-05 01:28:14 +00:00
render(
<div style={{ display: 'flex', flex: 1, height: '100%' }}>
<Provider {...stores}>
2017-05-17 07:11:13 +00:00
<Router>
<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} />
2017-05-17 07:11:13 +00:00
<Auth>
<Switch>
<Route exact path="/dashboard" component={Dashboard} />
<Route exact path="/collections/:id" component={Collection} />
2017-05-17 07:11:13 +00:00
<Route exact path="/d/:id" component={Document} />
<Route exact path="/d/:id/:edit" component={Document} />
2017-05-17 07:11:13 +00:00
<Route
exact
path="/collections/:id/new"
component={DocumentNew}
/>
<Route exact path="/d/:id/new" component={DocumentNewChild} />
2016-07-18 03:59:32 +00:00
2017-05-17 07:11:13 +00:00
<Route exact path="/search" component={Search} />
<Route exact path="/search/:query" component={Search} />
2017-05-17 07:11:13 +00:00
<Route exact path="/settings" component={Settings} />
2016-08-03 11:55:56 +00:00
2017-05-17 07:11:13 +00:00
<Route
exact
path="/keyboard-shortcuts"
component={KeyboardShortcuts}
/>
<Route exact path="/developers" component={Api} />
2016-09-15 03:50:59 +00:00
2017-05-17 07:11:13 +00:00
<Route path="/404" component={Error404} />
<Route component={notFoundSearch} />
</Switch>
</Auth>
</Switch>
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')
);