2016-10-11 10:46:24 +02:00
|
|
|
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';
|
2016-11-01 14:35:20 +01:00
|
|
|
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';
|
2016-11-01 14:35:20 +01:00
|
|
|
import FontIcon from 'react-toolbox/lib/font_icon';
|
2016-09-16 12:54:26 +02:00
|
|
|
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 {
|
|
|
|
|
2016-10-11 10:46:24 +02:00
|
|
|
static propTypes = {
|
2016-11-01 14:35:20 +01:00
|
|
|
user: ImmutablePropTypes.map.isRequired,
|
2016-10-11 11:34:28 +02:00
|
|
|
collections: ImmutablePropTypes.orderedMap.isRequired,
|
2016-10-11 10:46:24 +02:00
|
|
|
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,
|
2016-11-01 14:35:20 +01:00
|
|
|
onLogoutClick: PropTypes.func.isRequired,
|
2016-10-11 10:46:24 +02:00
|
|
|
};
|
|
|
|
|
2016-09-15 18:56:08 +02:00
|
|
|
state = {
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: false,
|
2016-11-01 14:35:20 +01:00
|
|
|
userMenuActive: false,
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-10-11 10:46:24 +02:00
|
|
|
handleCreatePostClick = (collectionName) => {
|
2016-09-15 18:56:08 +02:00
|
|
|
const { onCreateEntryClick } = this.props;
|
|
|
|
if (onCreateEntryClick) {
|
|
|
|
onCreateEntryClick(collectionName);
|
|
|
|
}
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-09-16 15:01:19 +02:00
|
|
|
handleCreateButtonClick = () => {
|
2016-09-15 18:56:08 +02:00
|
|
|
this.setState({
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: true,
|
2016-09-15 18:56:08 +02:00
|
|
|
});
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-09-16 15:01:19 +02:00
|
|
|
handleCreateMenuHide = () => {
|
2016-09-15 18:56:08 +02:00
|
|
|
this.setState({
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: false,
|
2016-09-15 18:56:08 +02:00
|
|
|
});
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
handleRightIconClick = () => {
|
|
|
|
this.setState({
|
|
|
|
userMenuActive: !this.state.userMenuActive,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-09-15 18:56:08 +02:00
|
|
|
render() {
|
2016-09-16 15:01:19 +02:00
|
|
|
const {
|
2016-11-01 14:35:20 +01:00
|
|
|
user,
|
2016-09-16 15:01:19 +02:00
|
|
|
collections,
|
|
|
|
commands,
|
|
|
|
defaultCommands,
|
|
|
|
runCommand,
|
2016-10-11 10:46:24 +02:00
|
|
|
toggleNavDrawer,
|
2016-11-01 14:35:20 +01:00
|
|
|
onLogoutClick,
|
2016-09-16 15:01:19 +02:00
|
|
|
} = this.props;
|
2016-11-01 14:35:20 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
createMenuActive,
|
|
|
|
userMenuActive,
|
|
|
|
} = this.state;
|
2016-09-15 18:56:08 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<AppBar
|
2016-10-03 16:57:48 +02:00
|
|
|
fixed
|
|
|
|
theme={styles}
|
2016-10-11 10:41:51 +02:00
|
|
|
leftIcon="menu"
|
2016-11-01 14:35:20 +01:00
|
|
|
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>
|
|
|
|
}
|
2016-10-11 10:41:51 +02:00
|
|
|
onLeftIconClick={toggleNavDrawer}
|
2016-11-01 14:35:20 +01:00
|
|
|
onRightIconClick={this.handleRightIconClick}
|
2016-09-15 18:56:08 +02:00
|
|
|
>
|
|
|
|
<IndexLink to="/">
|
2016-11-01 14:35:20 +01:00
|
|
|
<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
|
2016-10-03 16:57:48 +02:00
|
|
|
commands={commands}
|
|
|
|
defaultCommands={defaultCommands}
|
|
|
|
runCommand={runCommand}
|
2016-09-15 18:56:08 +02:00
|
|
|
/>
|
2016-11-01 14:35:20 +01:00
|
|
|
<IconMenu
|
|
|
|
theme={styles}
|
2016-10-11 10:41:51 +02:00
|
|
|
active={createMenuActive}
|
2016-11-01 14:35:20 +01:00
|
|
|
icon="create"
|
|
|
|
onClick={this.handleCreateButtonClick}
|
2016-10-11 10:41:51 +02:00
|
|
|
onHide={this.handleCreateMenuHide}
|
2016-09-15 18:56:08 +02:00
|
|
|
>
|
2016-10-05 18:55:35 +02:00
|
|
|
{
|
|
|
|
collections.valueSeq().map(collection =>
|
|
|
|
<MenuItem
|
2016-10-11 10:41:51 +02:00
|
|
|
key={collection.get('name')}
|
|
|
|
value={collection.get('name')}
|
2016-10-11 10:46:24 +02:00
|
|
|
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))} // eslint-disable-line
|
2016-10-11 10:41:51 +02:00
|
|
|
caption={pluralize(collection.get('label'), 1)}
|
2016-10-05 18:55:35 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2016-11-01 14:35:20 +01:00
|
|
|
</IconMenu>
|
2016-09-15 18:56:08 +02:00
|
|
|
</AppBar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|