// @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 classNames from 'classnames/bind'; import searchIcon from 'assets/icons/search.svg'; import { Flex } from 'reflexbox'; import { textColor } from 'styles/constants.scss'; import styles from './Layout.scss'; import DropdownMenu, { MenuItem } from 'components/DropdownMenu'; import LoadingIndicator from 'components/LoadingIndicator'; import UserStore from 'stores/UserStore'; const cx = classNames.bind(styles); type Props = { history: Object, children?: ?React.Element, actions?: ?React.Element, title?: ?React.Element, titleText?: string, loading?: boolean, user: UserStore, search: ?boolean, notifications?: React.Element, }; @observer class Layout extends React.Component { props: Props; static defaultProps = { search: true, }; @keydown(['/', 't']) search() { if (!this.props.user) return; _.defer(() => this.props.history.push('/search')); } @keydown(['d']) dashboard() { if (!this.props.user) return; _.defer(() => this.props.history.push('/')); } render() { const user = this.props.user; const handleLogout = () => { user.logout(() => this.props.history.push('/')); }; return (
{this.props.loading && } {this.props.notifications}
Atlas {this.props.title}
{this.props.actions} {user.user && {this.props.search &&
Search
} }> Settings Keyboard shortcuts API Logout
}
{this.props.children}
); } } const Avatar = styled.img` width: 24px; height: 24px; border-radius: 50%; `; const MenuLink = styled(Link)` color: ${textColor}; `; export default withRouter(inject('user')(Layout));