// @flow import React from 'react'; import { Link, withRouter } from 'react-router-dom'; import Helmet from 'react-helmet'; import styled from 'styled-components'; import { observer, inject } from 'mobx-react'; import _ from 'lodash'; import keydown from 'react-keydown'; import searchIcon from 'assets/icons/search.svg'; import { Flex } from 'reflexbox'; import { textColor, headerHeight } from 'styles/constants.scss'; import DropdownMenu, { MenuItem } from 'components/DropdownMenu'; import LoadingIndicator from 'components/LoadingIndicator'; import UserStore from 'stores/UserStore'; import AuthStore from 'stores/AuthStore'; type Props = { history: Object, children?: ?React.Element, actions?: ?React.Element, title?: ?React.Element, loading?: boolean, user: UserStore, auth: AuthStore, search: ?boolean, notifications?: React.Element, }; @observer class Layout extends React.Component { props: Props; static defaultProps = { search: true, }; @keydown(['/', 't']) search() { if (this.props.auth.isAuthenticated) _.defer(() => this.props.history.push('/search')); } @keydown(['d']) dashboard() { if (this.props.auth.isAuthenticated) _.defer(() => this.props.history.push('/')); } handleLogout = () => { this.props.auth.logout(() => this.props.history.push('/')); }; render() { const { auth, user } = this.props; return ( {this.props.loading && } {this.props.notifications}
Atlas {this.props.title} {this.props.actions} {auth.authenticated && user && {this.props.search && } }> Settings Keyboard shortcuts API Logout }
{this.props.children}
); } } const Container = styled(Flex)` width: 100%; height: 100%; `; const Header = styled(Flex)` display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 1; background: #fff; height: ${headerHeight}; border-bottom: 1px solid #eee; font-size: 14px; line-height: 1; `; const LogoLink = styled(Link)` font-family: 'Atlas Grotesk'; font-weight: bold; color: ${textColor}; text-decoration: none; font-size: 16px; `; const Title = styled.span` color: #ccc; a { color: #ccc; } a:hover { color: ${textColor}; } `; const Search = styled(Flex)` margin: 0 5px; padding: 15px 5px 0 5px; cursor: pointer; `; const SearchIcon = styled.img` height: 20px; `; const Avatar = styled.img` width: 24px; height: 24px; border-radius: 50%; `; const MenuLink = styled(Link)` color: ${textColor}; `; const Content = styled(Flex)` height: 100%; overflow: scroll; `; export default withRouter(inject('user', 'auth')(Layout));