2019-07-09 04:56:11 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-07-19 05:03:57 +01:00
|
|
|
import { connect } from 'react-redux';
|
2019-07-09 04:56:11 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-19 05:03:57 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-07-09 04:56:11 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import Icon from 'gabsocial/components/icon';
|
2019-07-19 05:03:57 +01:00
|
|
|
import { me } from 'gabsocial/initial_state';
|
|
|
|
import { fetchLists } from 'gabsocial/actions/lists';
|
|
|
|
import { createSelector } from 'reselect';
|
2019-07-09 04:56:11 +01: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 05:03:57 +01:00
|
|
|
listTitle: { id: 'home_column.lists', defaultMessage: 'Lists' },
|
2019-07-09 04:56:11 +01:00
|
|
|
});
|
|
|
|
|
2019-07-19 05:03:57 +01: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-07-09 04:56:11 +01:00
|
|
|
class ColumnHeader extends React.PureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
2019-07-19 05:03:57 +01:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-07-09 04:56:11 +01:00
|
|
|
active: PropTypes.bool,
|
|
|
|
children: PropTypes.node,
|
|
|
|
activeItem: PropTypes.string,
|
2019-07-19 05:03:57 +01:00
|
|
|
activeSubItem: PropTypes.string,
|
|
|
|
lists: ImmutablePropTypes.list,
|
2019-07-09 04:56:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
collapsed: true,
|
|
|
|
animating: false,
|
2019-07-19 05:03:57 +01:00
|
|
|
expandedFor: null, //lists, groups, etc.
|
2019-07-09 04:56:11 +01:00
|
|
|
};
|
|
|
|
|
2019-07-19 05:03:57 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.dispatch(fetchLists());
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
handleToggleClick = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.setState({ collapsed: !this.state.collapsed, animating: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleTransitionEnd = () => {
|
|
|
|
this.setState({ animating: false });
|
|
|
|
}
|
|
|
|
|
2019-07-19 05:03:57 +01:00
|
|
|
expandLists = () => {
|
|
|
|
this.setState({
|
|
|
|
expandedFor: 'lists',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
render () {
|
2019-07-19 05:03:57 +01:00
|
|
|
const { active, children, intl: { formatMessage }, activeItem, activeSubItem, lists } = this.props;
|
|
|
|
const { collapsed, animating, expandedFor } = this.state;
|
2019-07-09 04:56:11 +01:00
|
|
|
|
|
|
|
const wrapperClassName = classNames('column-header__wrapper', {
|
|
|
|
'active': active,
|
|
|
|
});
|
|
|
|
|
|
|
|
const buttonClassName = classNames('column-header', {
|
|
|
|
'active': active,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsibleClassName = classNames('column-header__collapsible', {
|
|
|
|
'collapsed': collapsed,
|
|
|
|
'animating': animating,
|
|
|
|
});
|
|
|
|
|
|
|
|
const collapsibleButtonClassName = classNames('column-header__button', {
|
|
|
|
'active': !collapsed,
|
|
|
|
});
|
|
|
|
|
2019-07-19 05:03:57 +01:00
|
|
|
const expansionClassName = classNames('column-header column-header__expansion', {
|
|
|
|
'open': expandedFor,
|
|
|
|
});
|
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
let extraContent, collapseButton;
|
|
|
|
|
|
|
|
if (children) {
|
|
|
|
extraContent = (
|
|
|
|
<div key='extra-content' className='column-header__collapsible__extra'>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
collapseButton = <button className={collapsibleButtonClassName} title={formatMessage(collapsed ? messages.show : messages.hide)} aria-label={formatMessage(collapsed ? messages.show : messages.hide)} aria-pressed={collapsed ? 'false' : 'true'} onClick={this.handleToggleClick}><Icon id='sliders' /></button>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const collapsedContent = [
|
|
|
|
extraContent,
|
|
|
|
];
|
|
|
|
|
2019-07-19 05:03:57 +01:00
|
|
|
let expandedContent = null;
|
|
|
|
if ((expandedFor === 'lists' || activeItem === 'lists') && lists) {
|
|
|
|
expandedContent = lists.map(list =>
|
|
|
|
<Link
|
|
|
|
key={list.get('id')}
|
|
|
|
to={`/list/${list.get('id')}`}
|
|
|
|
className={
|
|
|
|
classNames('btn btn--sub grouped', {
|
|
|
|
'active': list.get('id') === activeSubItem
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{list.get('title')}
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
return (
|
|
|
|
<div className={wrapperClassName}>
|
|
|
|
<h1 className={buttonClassName}>
|
|
|
|
<Link to='/home' className={classNames('btn grouped', {'active': 'home' === activeItem})}>
|
|
|
|
<Icon id='home' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.homeTitle)}
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<Link to='/timeline/all' className={classNames('btn grouped', {'active': 'all' === activeItem})}>
|
|
|
|
<Icon id='globe' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.allTitle)}
|
|
|
|
</Link>
|
|
|
|
|
2019-07-19 05:20:33 +01:00
|
|
|
{ lists.size > 0 &&
|
2019-07-19 05:03:57 +01:00
|
|
|
<a onClick={this.expandLists} className={classNames('btn grouped', {'active': 'lists' === activeItem})}>
|
|
|
|
<Icon id='list' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.listTitle)}
|
|
|
|
</a>
|
|
|
|
}
|
2019-07-19 05:20:33 +01:00
|
|
|
{ lists.size == 0 &&
|
|
|
|
<Link to='/lists' className='btn grouped'>
|
|
|
|
<Icon id='list' fixedWidth className='column-header__icon' />
|
|
|
|
{formatMessage(messages.listTitle)}
|
|
|
|
</Link>
|
|
|
|
}
|
2019-07-19 05:03:57 +01:00
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
<div className='column-header__buttons'>
|
|
|
|
{collapseButton}
|
|
|
|
</div>
|
|
|
|
</h1>
|
|
|
|
|
2019-07-19 05:03:57 +01:00
|
|
|
{
|
|
|
|
expandedContent &&
|
|
|
|
<h1 className={expansionClassName}>
|
|
|
|
{expandedContent}
|
|
|
|
</h1>
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:56:11 +01:00
|
|
|
<div className={collapsibleClassName} tabIndex={collapsed ? -1 : null} onTransitionEnd={this.handleTransitionEnd}>
|
|
|
|
<div className='column-header__collapsible-inner'>
|
|
|
|
{(!collapsed || animating) && collapsedContent}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-19 05:03:57 +01:00
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(ColumnHeader));
|