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

122 lines
3.3 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';
2016-07-18 03:59:32 +00:00
import { browserHistory, Link } from 'react-router';
2016-06-06 06:57:58 +00:00
import Helmet from 'react-helmet';
2017-05-02 05:01:50 +00:00
import styled from 'styled-components';
2017-04-27 05:18:36 +00:00
import { observer, inject } from 'mobx-react';
2016-07-23 20:12:56 +00:00
import _ from 'lodash';
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';
import classNames from 'classnames/bind';
import searchIcon from 'assets/icons/search.svg';
2017-05-10 07:02:11 +00:00
import { Flex } from 'reflexbox';
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 from './Layout.scss';
2016-05-30 18:36:43 +00:00
import DropdownMenu, { MenuItem } from 'components/DropdownMenu';
2016-05-29 18:01:48 +00:00
import LoadingIndicator from 'components/LoadingIndicator';
2017-05-12 00:23:56 +00:00
import UserStore from 'stores/UserStore';
2016-04-30 18:46:32 +00:00
2016-05-18 06:53:05 +00:00
const cx = classNames.bind(styles);
2016-04-29 05:25:37 +00:00
2017-05-12 00:23:56 +00:00
type Props = {
children?: ?React.Element<any>,
actions?: ?React.Element<any>,
title?: ?React.Element<any>,
titleText?: string,
loading?: boolean,
user: UserStore,
search: ?boolean,
notifications?: React.Element<any>,
};
@observer class Layout extends React.Component {
props: Props;
2016-07-18 03:59:32 +00:00
static defaultProps = {
search: true,
2017-04-27 05:18:36 +00:00
};
2016-07-18 03:59:32 +00:00
@keydown(['/', 't'])
search() {
2016-09-13 07:33:53 +00:00
// if (!this.props.user) return;
2016-07-23 20:12:56 +00:00
_.defer(() => browserHistory.push('/search'));
}
2016-07-19 07:31:01 +00:00
2016-07-23 20:12:56 +00:00
@keydown(['d'])
dashboard() {
2016-09-13 07:33:53 +00:00
// if (!this.props.user) return;
2016-07-23 20:12:56 +00:00
_.defer(() => browserHistory.push('/'));
2016-04-29 05:25:37 +00:00
}
render() {
const user = this.props.user;
2016-04-29 05:25:37 +00:00
return (
2017-04-27 05:18:36 +00:00
<div className={styles.container}>
2016-06-06 06:57:58 +00:00
<Helmet
2017-04-27 05:18:36 +00:00
title={
this.props.titleText ? `${this.props.titleText} - Atlas` : 'Atlas'
}
2017-05-13 23:00:50 +00:00
meta={[
{
name: 'viewport',
content: 'width=device-width, initial-scale=1.0',
},
]}
2016-06-06 06:57:58 +00:00
/>
2017-04-27 05:18:36 +00:00
{this.props.loading && <LoadingIndicator />}
2016-08-19 15:02:56 +00:00
2017-04-27 05:18:36 +00:00
{this.props.notifications}
2017-04-27 05:18:36 +00:00
<div className={cx(styles.header)}>
<div className={styles.headerLeft}>
<Link to="/" className={styles.team}>Atlas</Link>
<span className={styles.title}>
{this.props.title}
2016-06-06 07:23:38 +00:00
</span>
2016-05-07 18:52:08 +00:00
</div>
2017-04-27 05:18:36 +00:00
<Flex className={styles.headerRight}>
2016-09-13 05:19:59 +00:00
<Flex>
2017-04-27 05:18:36 +00:00
<Flex align="center" className={styles.actions}>
{this.props.actions}
2016-07-18 03:59:32 +00:00
</Flex>
2017-04-27 05:18:36 +00:00
{user.user &&
2016-09-13 05:19:59 +00:00
<Flex>
2017-04-27 05:18:36 +00:00
{this.props.search &&
2016-09-13 05:19:59 +00:00
<Flex>
<div
2017-04-27 05:18:36 +00:00
onClick={this.search}
className={styles.search}
2016-09-13 05:19:59 +00:00
title="Search (/)"
>
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
<img src={searchIcon} alt="Search" />
2016-09-13 05:19:59 +00:00
</div>
2017-04-27 05:18:36 +00:00
</Flex>}
2017-05-02 05:01:50 +00:00
<DropdownMenu label={<Avatar src={user.user.avatarUrl} />}>
2016-09-13 05:19:59 +00:00
<MenuItem to="/settings">Settings</MenuItem>
2017-04-27 05:18:36 +00:00
<MenuItem to="/keyboard-shortcuts">
Keyboard shortcuts
</MenuItem>
2016-09-15 03:50:59 +00:00
<MenuItem to="/developers">API</MenuItem>
2017-04-27 05:18:36 +00:00
<MenuItem onClick={user.logout}>Logout</MenuItem>
2016-09-13 05:19:59 +00:00
</DropdownMenu>
2017-04-27 05:18:36 +00:00
</Flex>}
2016-09-13 05:19:59 +00:00
</Flex>
2016-05-07 19:20:09 +00:00
</Flex>
2016-04-29 05:25:37 +00:00
</div>
2016-05-30 18:36:43 +00:00
2017-04-27 05:18:36 +00:00
<div className={cx(styles.content)}>
{this.props.children}
2016-04-29 05:25:37 +00:00
</div>
</div>
);
}
}
2017-05-02 05:01:50 +00:00
const Avatar = styled.img`
width: 24px;
height: 24px;
border-radius: 50%;
`;
2017-05-12 00:23:56 +00:00
export default inject('user')(Layout);