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/app/components/Layout/Layout.js

142 lines
3.6 KiB
JavaScript
Raw Normal View History

2017-05-12 00:23:56 +00:00
// @flow
2016-04-29 05:25:37 +00:00
import React from 'react';
2018-03-05 06:38:14 +00:00
import { Switch, Route, withRouter } from 'react-router-dom';
import type { Location } from 'react-router-dom';
2017-10-22 23:33:10 +00:00
import { Helmet } from 'react-helmet';
2017-05-02 05:01:50 +00:00
import styled from 'styled-components';
import breakpoint from 'styled-components-breakpoint';
2017-04-27 05:18:36 +00:00
import { observer, inject } from 'mobx-react';
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 keydown from 'react-keydown';
2017-11-09 08:17:55 +00:00
import Analytics from 'shared/components/Analytics';
import Flex from 'shared/components/Flex';
2017-11-19 23:56:50 +00:00
import { layout } from 'shared/styles/constants';
import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers';
2017-09-04 00:27:12 +00:00
2017-06-30 05:44:15 +00:00
import { LoadingIndicatorBar } from 'components/LoadingIndicator';
2017-11-19 23:56:50 +00:00
import Sidebar from 'components/Sidebar';
import SettingsSidebar from 'components/Sidebar/Settings';
2017-11-19 23:56:50 +00:00
import Modals from 'components/Modals';
import Toasts from 'components/Toasts';
import ErrorSuspended from 'scenes/ErrorSuspended';
2017-06-16 03:39:08 +00:00
2017-05-30 02:08:03 +00:00
import AuthStore from 'stores/AuthStore';
2017-06-16 03:39:08 +00:00
import UiStore from 'stores/UiStore';
import DocumentsStore from 'stores/DocumentsStore';
2016-04-30 18:46:32 +00:00
2017-05-12 00:23:56 +00:00
type Props = {
2017-05-17 07:11:13 +00:00
history: Object,
location: Location,
documents: DocumentsStore,
2017-05-12 00:23:56 +00:00
children?: ?React.Element<any>,
actions?: ?React.Element<any>,
title?: ?React.Element<any>,
2017-05-30 02:08:03 +00:00
auth: AuthStore,
2017-06-16 03:39:08 +00:00
ui: UiStore,
2017-05-12 00:23:56 +00:00
notifications?: React.Element<any>,
};
2017-11-10 22:14:30 +00:00
@observer
class Layout extends React.Component {
2017-05-12 00:23:56 +00:00
props: Props;
2017-10-15 18:42:03 +00:00
scrollable: ?HTMLDivElement;
2016-07-18 03:59:32 +00:00
@keydown(['/', 't'])
goToSearch(ev) {
ev.preventDefault();
ev.stopPropagation();
this.props.history.push(searchUrl());
2016-07-23 20:12:56 +00:00
}
2016-07-19 07:31:01 +00:00
@keydown('d')
goToDashboard() {
this.props.history.push(homeUrl());
}
@keydown('e')
goToEdit(ev) {
const activeDocument = this.props.documents.active;
if (!activeDocument) return;
ev.preventDefault();
ev.stopPropagation();
this.props.history.push(documentEditUrl(activeDocument));
2016-04-29 05:25:37 +00:00
}
@keydown('shift+/')
2017-09-29 06:22:09 +00:00
openKeyboardShortcuts() {
this.props.ui.setActiveModal('keyboard-shortcuts');
}
2017-05-30 02:08:03 +00:00
render() {
2017-11-19 23:56:50 +00:00
const { auth, ui } = this.props;
2017-09-04 00:08:56 +00:00
const { user, team } = auth;
2017-11-19 23:56:50 +00:00
const showSidebar = auth.authenticated && user && team;
2017-05-17 07:11:13 +00:00
2018-03-05 06:38:14 +00:00
if (auth.isSuspended) return <ErrorSuspended />;
2016-04-29 05:25:37 +00:00
return (
<Container column auto>
2017-10-22 23:33:10 +00:00
<Helmet>
2017-11-09 08:20:22 +00:00
<title>Outline</title>
2017-10-22 23:33:10 +00:00
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
2017-11-27 04:34:28 +00:00
<link
rel="shortcut icon"
type="image/png"
href="/favicon-16.png"
sizes="16x16"
/>
<link
rel="shortcut icon"
type="image/png"
href="/favicon-32.png"
sizes="32x32"
/>
2017-10-22 23:33:10 +00:00
</Helmet>
2017-11-09 08:17:55 +00:00
<Analytics />
2016-06-06 06:57:58 +00:00
2017-06-30 05:44:15 +00:00
{this.props.ui.progressBarVisible && <LoadingIndicatorBar />}
2017-04-27 05:18:36 +00:00
{this.props.notifications}
2017-06-16 03:39:08 +00:00
<Flex auto>
{showSidebar && (
<Switch>
<Route path="/settings" component={SettingsSidebar} />
<Route component={Sidebar} />
</Switch>
)}
2017-06-16 03:39:08 +00:00
2017-06-25 07:29:40 +00:00
<Content auto justify="center" editMode={ui.editMode}>
2017-06-16 03:39:08 +00:00
{this.props.children}
</Content>
</Flex>
2017-09-10 05:12:59 +00:00
<Modals ui={ui} />
<Toasts />
</Container>
2016-04-29 05:25:37 +00:00
);
}
}
const Container = styled(Flex)`
2017-06-09 06:32:08 +00:00
position: relative;
width: 100%;
height: 100%;
`;
const Content = styled(Flex)`
margin: 0;
transition: margin-left 200ms ease-in-out;
2017-12-03 00:27:45 +00:00
@media print {
margin: 0;
2017-12-03 00:27:45 +00:00
}
${breakpoint('tablet')`
margin-left: ${props => (props.editMode ? 0 : layout.sidebarWidth)};
`};
`;
2017-11-19 23:56:50 +00:00
export default withRouter(inject('user', 'auth', 'ui', 'documents')(Layout));