125 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
2016-09-15 18:56:08 +02:00
import pluralize from 'pluralize';
import { IndexLink } from 'react-router';
import { IconMenu, Menu, MenuItem } from 'react-toolbox/lib/menu';
import Avatar from 'react-toolbox/lib/avatar';
2016-09-15 18:56:08 +02:00
import AppBar from 'react-toolbox/lib/app_bar';
import FontIcon from 'react-toolbox/lib/font_icon';
import FindBar from '../FindBar/FindBar';
2016-09-15 18:56:08 +02:00
import styles from './AppHeader.css';
export default class AppHeader extends React.Component {
static propTypes = {
user: ImmutablePropTypes.map.isRequired,
2016-10-11 11:34:28 +02:00
collections: ImmutablePropTypes.orderedMap.isRequired,
commands: PropTypes.array.isRequired, // eslint-disable-line
defaultCommands: PropTypes.array.isRequired, // eslint-disable-line
runCommand: PropTypes.func.isRequired,
toggleNavDrawer: PropTypes.func.isRequired,
onCreateEntryClick: PropTypes.func.isRequired,
onLogoutClick: PropTypes.func.isRequired,
};
2016-09-15 18:56:08 +02:00
state = {
createMenuActive: false,
userMenuActive: false,
};
2016-09-15 18:56:08 +02:00
handleCreatePostClick = (collectionName) => {
2016-09-15 18:56:08 +02:00
const { onCreateEntryClick } = this.props;
if (onCreateEntryClick) {
onCreateEntryClick(collectionName);
}
};
2016-09-15 18:56:08 +02:00
handleCreateButtonClick = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: true,
2016-09-15 18:56:08 +02:00
});
};
2016-09-15 18:56:08 +02:00
handleCreateMenuHide = () => {
2016-09-15 18:56:08 +02:00
this.setState({
createMenuActive: false,
2016-09-15 18:56:08 +02:00
});
};
2016-09-15 18:56:08 +02:00
handleRightIconClick = () => {
this.setState({
userMenuActive: !this.state.userMenuActive,
});
};
2016-09-15 18:56:08 +02:00
render() {
const {
user,
collections,
commands,
defaultCommands,
runCommand,
toggleNavDrawer,
onLogoutClick,
} = this.props;
const {
createMenuActive,
userMenuActive,
} = this.state;
2016-09-15 18:56:08 +02:00
return (
<AppBar
fixed
theme={styles}
leftIcon="menu"
rightIcon={
<div>
<Avatar
title={user.get('name')}
image={user.get('avatar_url')}
/>
<Menu
active={userMenuActive}
position="topRight"
onHide={this.handleRightIconClick}
>
<MenuItem onClick={onLogoutClick}>Log out</MenuItem>
</Menu>
</div>
}
onLeftIconClick={toggleNavDrawer}
onRightIconClick={this.handleRightIconClick}
2016-09-15 18:56:08 +02:00
>
<IndexLink to="/">
<FontIcon value="home" />
2016-09-15 18:56:08 +02:00
</IndexLink>
2016-10-06 15:13:31 +02:00
2016-09-15 18:56:08 +02:00
<FindBar
commands={commands}
defaultCommands={defaultCommands}
runCommand={runCommand}
2016-09-15 18:56:08 +02:00
/>
<IconMenu
theme={styles}
active={createMenuActive}
icon="create"
onClick={this.handleCreateButtonClick}
onHide={this.handleCreateMenuHide}
2016-09-15 18:56:08 +02:00
>
{
collections.valueSeq().map(collection =>
<MenuItem
key={collection.get('name')}
value={collection.get('name')}
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))} // eslint-disable-line
caption={pluralize(collection.get('label'), 1)}
/>
)
}
</IconMenu>
2016-09-15 18:56:08 +02:00
</AppBar>
);
}
}