2019-07-19 00:03:57 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-08-03 02:00:45 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-07-08 23:56:11 -04:00
|
|
|
import classNames from 'classnames';
|
2019-08-03 02:00:45 -04:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl';
|
2019-07-08 23:56:11 -04:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-07-19 00:03:57 -04:00
|
|
|
import { createSelector } from 'reselect';
|
2019-08-03 02:00:45 -04:00
|
|
|
import Icon from '../icon';
|
|
|
|
import { fetchLists } from '../../actions/lists';
|
|
|
|
|
|
|
|
import './index.scss';
|
2019-07-08 23:56:11 -04:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
|
|
|
|
hide: { id: 'column_header.hide_settings', defaultMessage: 'Hide settings' },
|
|
|
|
homeTitle: { id: 'home_column_header.home', defaultMessage: 'Home' },
|
|
|
|
allTitle: { id: 'home_column_header.all', defaultMessage: 'All' },
|
2019-07-19 00:03:57 -04:00
|
|
|
listTitle: { id: 'home_column.lists', defaultMessage: 'Lists' },
|
2019-07-08 23:56:11 -04:00
|
|
|
});
|
|
|
|
|
2019-07-19 00:03:57 -04:00
|
|
|
const getOrderedLists = createSelector([state => state.get('lists')], lists => {
|
|
|
|
if (!lists) {
|
|
|
|
return lists;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
|
|
|
lists: getOrderedLists(state),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-08-03 02:00:45 -04:00
|
|
|
class ColumnHeader extends ImmutablePureComponent {
|
2019-07-08 23:56:11 -04:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
2019-07-19 00:03:57 -04:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-07-08 23:56:11 -04:00
|
|
|
active: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
|
|
|
activeItem: PropTypes.string,
|
2019-07-19 00:03:57 -04:00
|
|
|
activeSubItem: PropTypes.string,
|
|
|
|
lists: ImmutablePropTypes.list,
|
2019-07-08 23:56:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
collapsed: true,
|
2019-08-03 02:00:45 -04:00
|
|
|
listsExpanded: false,
|
2019-07-08 23:56:11 -04:00
|
|
|
};
|
|
|
|
|
2019-07-19 00:03:57 -04:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.dispatch(fetchLists());
|
|
|
|
}
|
|
|
|
|
2019-07-08 23:56:11 -04:00
|
|
|
handleToggleClick = (e) => {
|
|
|
|
e.stopPropagation();
|
2019-08-03 02:00:45 -04:00
|
|
|
this.setState({ collapsed: !this.state.collapsed });
|
2019-07-08 23:56:11 -04:00
|
|
|
}
|
|
|
|
|
2019-07-19 00:03:57 -04:00
|
|
|
expandLists = () => {
|
2019-08-03 02:00:45 -04:00
|
|
|
this.setState({ listsExpanded: !this.state.listsExpanded });
|
2019-07-19 00:03:57 -04:00
|
|
|
}
|
|
|
|
|
2019-07-08 23:56:11 -04:00
|
|
|
render () {
|
2019-07-19 00:03:57 -04:00
|
|
|
const { active, children, intl: { formatMessage }, activeItem, activeSubItem, lists } = this.props;
|
2019-08-03 02:00:45 -04:00
|
|
|
const { collapsed, listsExpanded } = this.state;
|
2019-07-08 23:56:11 -04:00
|
|
|
|
|
|
|
const wrapperClassName = classNames('column-header__wrapper', {
|
2019-08-03 02:00:45 -04:00
|
|
|
'column-header__wrapper--active': active,
|
2019-07-08 23:56:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const buttonClassName = classNames('column-header', {
|
2019-08-03 02:00:45 -04:00
|
|
|
'column-header--active': active,
|
2019-07-08 23:56:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const collapsibleClassName = classNames('column-header__collapsible', {
|
2019-08-03 02:00:45 -04:00
|
|
|
'column-header__collapsible--collapsed': collapsed,
|
2019-07-08 23:56:11 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const collapsibleButtonClassName = classNames('column-header__button', {
|
2019-08-03 02:00:45 -04:00
|
|
|
'column-header__button--active': !collapsed,
|
2019-07-08 23:56:11 -04:00
|
|
|
});
|
|
|
|
|
2019-07-19 00:03:57 -04:00
|
|
|
const expansionClassName = classNames('column-header column-header__expansion', {
|
2019-08-03 02:00:45 -04:00
|
|
|
'column-header__expansion--open': listsExpanded,
|
2019-07-19 00:03:57 -04:00
|
|
|
});
|
|
|
|
|
2019-08-03 02:00:45 -04:00
|
|
|
const btnTitle = formatMessage(collapsed ? messages.show : messages.hide);
|
2019-07-08 23:56:11 -04:00
|
|
|
|
2019-07-19 00:03:57 -04:00
|
|
|
let expandedContent = null;
|
2019-08-03 02:00:45 -04:00
|
|
|
if ((listsExpanded || activeItem === 'lists') && lists) {
|
|
|
|
expandedContent = lists.map((list) => {
|
|
|
|
const listId = list.get('id');
|
|
|
|
const linkUrl = `/list/${listId}`;
|
|
|
|
const classes = classNames('column-header-btn column-header-btn--sub column-header-btn--grouped', {
|
|
|
|
'column-header-btn--active': listId === activeSubItem,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Link key={listId} to={linkUrl} className={classes}>
|
|
|
|
{list.get('title')}
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
});
|
2019-07-19 00:03:57 -04:00
|
|
|
}
|
|
|
|
|
2019-07-08 23:56:11 -04:00
|
|
|
return (
|
|
|
|
<div className={wrapperClassName}>
|
|
|
|
<h1 className={buttonClassName}>
|
2019-08-03 02:00:45 -04:00
|
|
|
<Link to='/home' className={classNames('column-header-btn column-header-btn--grouped', { 'column-header-btn--active': 'home' === activeItem })}>
|
2019-07-08 23:56:11 -04:00
|
|
|
<Icon id='home' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.homeTitle)}
|
|
|
|
</Link>
|
|
|
|
|
2019-08-03 02:00:45 -04:00
|
|
|
<Link to='/timeline/all' className={classNames('column-header-btn column-header-btn--grouped', { 'column-header-btn--active': 'all' === activeItem })}>
|
2019-07-08 23:56:11 -04:00
|
|
|
<Icon id='globe' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.allTitle)}
|
|
|
|
</Link>
|
|
|
|
|
2019-07-19 00:20:33 -04:00
|
|
|
{ lists.size > 0 &&
|
2019-08-03 02:00:45 -04:00
|
|
|
<a onClick={this.expandLists} className={classNames('column-header-btn column-header-btn--grouped', { 'column-header-btn--active': 'lists' === activeItem })}>
|
2019-07-19 00:03:57 -04:00
|
|
|
<Icon id='list' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.listTitle)}
|
|
|
|
</a>
|
|
|
|
}
|
2019-07-19 00:20:33 -04:00
|
|
|
{ lists.size == 0 &&
|
2019-08-03 02:00:45 -04:00
|
|
|
<Link to='/lists' className='column-header-btn column-header-btn--grouped'>
|
2019-07-19 00:20:33 -04:00
|
|
|
<Icon id='list' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.listTitle)}
|
|
|
|
</Link>
|
|
|
|
}
|
2019-07-19 00:03:57 -04:00
|
|
|
|
2019-07-08 23:56:11 -04:00
|
|
|
<div className='column-header__buttons'>
|
2019-08-03 02:00:45 -04:00
|
|
|
<button
|
|
|
|
className={collapsibleButtonClassName}
|
|
|
|
title={btnTitle}
|
|
|
|
aria-label={btnTitle}
|
|
|
|
aria-pressed={collapsed ? 'false' : 'true'}
|
|
|
|
onClick={this.handleToggleClick}
|
|
|
|
>
|
|
|
|
<Icon id='sliders' />
|
|
|
|
</button>
|
2019-07-08 23:56:11 -04:00
|
|
|
</div>
|
|
|
|
</h1>
|
|
|
|
|
2019-08-03 02:00:45 -04:00
|
|
|
<h1 className={expansionClassName}>
|
|
|
|
{expandedContent}
|
|
|
|
</h1>
|
2019-07-19 00:03:57 -04:00
|
|
|
|
2019-08-03 02:00:45 -04:00
|
|
|
<div className={collapsibleClassName} tabIndex={collapsed ? -1 : null}>
|
2019-07-08 23:56:11 -04:00
|
|
|
<div className='column-header__collapsible-inner'>
|
2019-08-03 02:00:45 -04:00
|
|
|
{
|
|
|
|
!collapsed &&
|
|
|
|
<div key='extra-content' className='column-header__collapsible__extra'>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
}
|
2019-07-08 23:56:11 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2019-08-03 02:00:45 -04:00
|
|
|
|
2019-07-08 23:56:11 -04:00
|
|
|
}
|
2019-07-19 00:03:57 -04:00
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(ColumnHeader));
|