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

124 lines
3.5 KiB
JavaScript
Raw Normal View History

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';
import { observer } from 'mobx-react';
2016-08-19 15:02:56 +00:00
import { injectOffline } from 'components/Offline';
2016-07-18 03:59:32 +00:00
import keydown from 'react-keydown';
2016-07-23 20:12:56 +00:00
import _ from 'lodash';
2016-04-29 05:25:37 +00:00
2016-05-30 18:36:43 +00:00
import DropdownMenu, { MenuItem } from 'components/DropdownMenu';
2016-08-05 15:44:15 +00:00
import { Flex } from 'reflexbox';
2016-05-29 18:01:48 +00:00
import LoadingIndicator from 'components/LoadingIndicator';
2016-08-03 12:32:04 +00:00
import Alert from 'components/Alert';
2016-05-30 18:36:43 +00:00
import { Avatar } from 'rebass';
2016-04-30 18:46:32 +00:00
2016-04-29 05:25:37 +00:00
import styles from './Layout.scss';
2016-05-18 06:53:05 +00:00
import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
2016-04-29 05:25:37 +00:00
@observer(['user'])
2016-08-19 15:02:56 +00:00
@injectOffline
2016-04-29 05:25:37 +00:00
class Layout extends React.Component {
static propTypes = {
2016-08-03 12:32:04 +00:00
children: React.PropTypes.node,
2016-05-10 06:07:50 +00:00
actions: React.PropTypes.node,
2016-05-15 21:44:17 +00:00
title: React.PropTypes.node,
2016-06-06 06:57:58 +00:00
titleText: React.PropTypes.node,
2016-05-29 18:01:48 +00:00
loading: React.PropTypes.bool,
user: React.PropTypes.object.isRequired,
2016-07-18 03:59:32 +00:00
search: React.PropTypes.bool,
2016-08-19 15:02:56 +00:00
offline: React.PropTypes.bool,
2016-07-18 03:59:32 +00:00
}
static defaultProps = {
search: true,
}
@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 (
<div className={ styles.container }>
2016-06-06 06:57:58 +00:00
<Helmet
2016-08-03 12:32:04 +00:00
title={ this.props.titleText
2016-08-03 13:57:09 +00:00
? `${this.props.titleText} - Atlas`
: 'Atlas' }
2016-06-06 06:57:58 +00:00
/>
2016-08-19 15:02:56 +00:00
{ this.props.loading && (
2016-05-29 18:01:48 +00:00
<LoadingIndicator />
2016-08-19 15:02:56 +00:00
) }
{ this.props.offline && (
<Alert offline>
It looks like you're offline. Reconnect to restore access to all of your documents 📚
</Alert>
) }
2016-08-03 12:32:04 +00:00
<div className={ cx(styles.header) }>
2016-06-06 07:05:21 +00:00
<div className={ styles.headerLeft }>
2016-09-15 03:57:04 +00:00
<Link to="/" className={ styles.team }>Atlas</Link>
2016-06-06 07:23:38 +00:00
<span className={ styles.title }>
2016-08-14 09:31:13 +00:00
{ this.props.title }
2016-06-06 07:23:38 +00:00
</span>
2016-05-07 18:52:08 +00:00
</div>
2016-08-05 15:44:15 +00:00
<Flex className={ styles.headerRight }>
2016-09-13 05:19:59 +00:00
<Flex>
<Flex align="center" className={ styles.actions }>
{ this.props.actions }
2016-07-18 03:59:32 +00:00
</Flex>
2016-09-13 05:19:59 +00:00
{ user.user && (
<Flex>
{ this.props.search && (
<Flex>
<div
onClick={ this.search }
className={ styles.search }
title="Search (/)"
>
<img src={ require('assets/icons/search.svg') } alt="Search" />
</div>
</Flex>
) }
<DropdownMenu
label={ <Avatar
circle
size={ 24 }
src={ user.user.avatarUrl }
/> }
>
<MenuItem to="/settings">Settings</MenuItem>
2016-09-15 03:50:59 +00:00
<MenuItem to="/keyboard-shortcuts">Keyboard shortcuts</MenuItem>
<MenuItem to="/developers">API</MenuItem>
2016-09-13 05:19:59 +00:00
<MenuItem onClick={ user.logout }>Logout</MenuItem>
</DropdownMenu>
</Flex>
) }
</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
<div
className={ cx(styles.content) }
>
2016-04-29 05:25:37 +00:00
{ this.props.children }
</div>
</div>
);
}
}
2016-07-18 03:59:32 +00:00
export default Layout;