You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
214 lines
7.4 KiB
214 lines
7.4 KiB
8 years ago
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import classNames from 'classnames';
|
||
8 years ago
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
||
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
|
||
7 years ago
|
import NotificationPurgeButtonsContainer from 'flavours/glitch/containers/notification_purge_buttons_container';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
8 years ago
|
show: { id: 'column_header.show_settings', defaultMessage: 'Show settings' },
|
||
|
hide: { id: 'column_header.hide_settings', defaultMessage: 'Hide settings' },
|
||
8 years ago
|
moveLeft: { id: 'column_header.moveLeft_settings', defaultMessage: 'Move column to the left' },
|
||
|
moveRight: { id: 'column_header.moveRight_settings', defaultMessage: 'Move column to the right' },
|
||
8 years ago
|
enterNotifCleaning : { id: 'notification_purge.start', defaultMessage: 'Enter notification cleaning mode' },
|
||
8 years ago
|
});
|
||
|
|
||
|
@injectIntl
|
||
8 years ago
|
export default class ColumnHeader extends React.PureComponent {
|
||
8 years ago
|
|
||
|
static contextTypes = {
|
||
|
router: PropTypes.object,
|
||
|
};
|
||
|
|
||
|
static propTypes = {
|
||
8 years ago
|
intl: PropTypes.object.isRequired,
|
||
8 years ago
|
title: PropTypes.node.isRequired,
|
||
8 years ago
|
icon: PropTypes.string.isRequired,
|
||
|
active: PropTypes.bool,
|
||
8 years ago
|
localSettings : ImmutablePropTypes.map,
|
||
8 years ago
|
multiColumn: PropTypes.bool,
|
||
8 years ago
|
focusable: PropTypes.bool,
|
||
8 years ago
|
showBackButton: PropTypes.bool,
|
||
8 years ago
|
notifCleaning: PropTypes.bool, // true only for the notification column
|
||
|
notifCleaningActive: PropTypes.bool,
|
||
8 years ago
|
onEnterCleaningMode: PropTypes.func,
|
||
8 years ago
|
children: PropTypes.node,
|
||
|
pinned: PropTypes.bool,
|
||
|
onPin: PropTypes.func,
|
||
|
onMove: PropTypes.func,
|
||
|
onClick: PropTypes.func,
|
||
8 years ago
|
intl: PropTypes.object.isRequired,
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
static defaultProps = {
|
||
|
focusable: true,
|
||
|
}
|
||
|
|
||
8 years ago
|
state = {
|
||
|
collapsed: true,
|
||
|
animating: false,
|
||
8 years ago
|
animatingNCD: false,
|
||
8 years ago
|
};
|
||
|
|
||
|
handleToggleClick = (e) => {
|
||
|
e.stopPropagation();
|
||
|
this.setState({ collapsed: !this.state.collapsed, animating: true });
|
||
|
}
|
||
|
|
||
|
handleTitleClick = () => {
|
||
|
this.props.onClick();
|
||
|
}
|
||
|
|
||
|
handleMoveLeft = () => {
|
||
|
this.props.onMove(-1);
|
||
|
}
|
||
|
|
||
|
handleMoveRight = () => {
|
||
|
this.props.onMove(1);
|
||
|
}
|
||
|
|
||
|
handleBackClick = () => {
|
||
8 years ago
|
// if history is exhausted, or we would leave mastodon, just go to root.
|
||
|
if (window.history && (window.history.length === 1 || window.history.length === window._mastoInitialHistoryLen)) {
|
||
|
this.context.router.history.push('/');
|
||
|
} else {
|
||
|
this.context.router.history.goBack();
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
handleTransitionEnd = () => {
|
||
|
this.setState({ animating: false });
|
||
|
}
|
||
|
|
||
8 years ago
|
handleTransitionEndNCD = () => {
|
||
|
this.setState({ animatingNCD: false });
|
||
|
}
|
||
|
|
||
|
onEnterCleaningMode = () => {
|
||
|
this.setState({ animatingNCD: true });
|
||
|
this.props.onEnterCleaningMode(!this.props.notifCleaningActive);
|
||
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
const { intl, icon, active, children, pinned, onPin, multiColumn, focusable, showBackButton, intl: { formatMessage }, notifCleaning, notifCleaningActive } = this.props;
|
||
8 years ago
|
const { collapsed, animating, animatingNCD } = this.state;
|
||
|
|
||
8 years ago
|
let title = this.props.title;
|
||
|
|
||
8 years ago
|
const wrapperClassName = classNames('column-header__wrapper', {
|
||
|
'active': active,
|
||
|
});
|
||
|
|
||
8 years ago
|
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,
|
||
|
});
|
||
|
|
||
8 years ago
|
const notifCleaningButtonClassName = classNames('column-header__button', {
|
||
|
'active': notifCleaningActive,
|
||
|
});
|
||
|
|
||
|
const notifCleaningDrawerClassName = classNames('ncd column-header__collapsible', {
|
||
|
'collapsed': !notifCleaningActive,
|
||
|
'animating': animatingNCD,
|
||
|
});
|
||
|
|
||
8 years ago
|
let extraContent, pinButton, moveButtons, backButton, collapseButton;
|
||
|
|
||
8 years ago
|
//*glitch
|
||
|
const msgEnterNotifCleaning = intl.formatMessage(messages.enterNotifCleaning);
|
||
|
|
||
8 years ago
|
if (children) {
|
||
|
extraContent = (
|
||
|
<div key='extra-content' className='column-header__collapsible__extra'>
|
||
|
{children}
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
if (multiColumn && pinned) {
|
||
|
pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={onPin}><i className='fa fa fa-times' /> <FormattedMessage id='column_header.unpin' defaultMessage='Unpin' /></button>;
|
||
|
|
||
|
moveButtons = (
|
||
|
<div key='move-buttons' className='column-header__setting-arrows'>
|
||
8 years ago
|
<button title={formatMessage(messages.moveLeft)} aria-label={formatMessage(messages.moveLeft)} className='text-btn column-header__setting-btn' onClick={this.handleMoveLeft}><i className='fa fa-chevron-left' /></button>
|
||
|
<button title={formatMessage(messages.moveRight)} aria-label={formatMessage(messages.moveRight)} className='text-btn column-header__setting-btn' onClick={this.handleMoveRight}><i className='fa fa-chevron-right' /></button>
|
||
8 years ago
|
</div>
|
||
|
);
|
||
|
} else if (multiColumn) {
|
||
|
pinButton = <button key='pin-button' className='text-btn column-header__setting-btn' onClick={onPin}><i className='fa fa fa-plus' /> <FormattedMessage id='column_header.pin' defaultMessage='Pin' /></button>;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
if (!pinned && (multiColumn || showBackButton)) {
|
||
8 years ago
|
backButton = (
|
||
|
<button onClick={this.handleBackClick} className='column-header__back-button'>
|
||
|
<i className='fa fa-fw fa-chevron-left column-back-button__icon' />
|
||
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
||
|
</button>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
const collapsedContent = [
|
||
|
extraContent,
|
||
|
];
|
||
|
|
||
|
if (multiColumn) {
|
||
|
collapsedContent.push(moveButtons);
|
||
|
collapsedContent.push(pinButton);
|
||
|
}
|
||
|
|
||
|
if (children || multiColumn) {
|
||
8 years ago
|
collapseButton = <button className={collapsibleButtonClassName} aria-label={formatMessage(collapsed ? messages.show : messages.hide)} aria-pressed={collapsed ? 'false' : 'true'} onClick={this.handleToggleClick}><i className='fa fa-sliders' /></button>;
|
||
8 years ago
|
}
|
||
|
|
||
|
return (
|
||
8 years ago
|
<div className={wrapperClassName}>
|
||
7 years ago
|
<h1 tabIndex={focusable ? 0 : null} role='button' className={buttonClassName} aria-label={title} onClick={this.handleTitleClick}>
|
||
8 years ago
|
<i className={`fa fa-fw fa-${icon} column-header__icon`} />
|
||
7 years ago
|
<span className='column-header__title'>
|
||
|
{title}
|
||
|
</span>
|
||
8 years ago
|
<div className='column-header__buttons'>
|
||
|
{backButton}
|
||
8 years ago
|
{ notifCleaning ? (
|
||
|
<button
|
||
|
aria-label={msgEnterNotifCleaning}
|
||
|
title={msgEnterNotifCleaning}
|
||
|
onClick={this.onEnterCleaningMode}
|
||
|
className={notifCleaningButtonClassName}
|
||
|
>
|
||
|
<i className='fa fa-eraser' />
|
||
|
</button>
|
||
|
) : null}
|
||
8 years ago
|
{collapseButton}
|
||
|
</div>
|
||
8 years ago
|
</h1>
|
||
8 years ago
|
|
||
8 years ago
|
{ notifCleaning ? (
|
||
|
<div className={notifCleaningDrawerClassName} onTransitionEnd={this.handleTransitionEndNCD}>
|
||
|
<div className='column-header__collapsible-inner nopad-drawer'>
|
||
|
{(notifCleaningActive || animatingNCD) ? (<NotificationPurgeButtonsContainer />) : null }
|
||
|
</div>
|
||
|
</div>
|
||
|
) : null}
|
||
|
|
||
7 years ago
|
<div className={collapsibleClassName} tabIndex={collapsed ? -1 : null} onTransitionEnd={this.handleTransitionEnd}>
|
||
8 years ago
|
<div className='column-header__collapsible-inner'>
|
||
8 years ago
|
{(!collapsed || animating) && collapsedContent}
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|