bigbuffet-rw/app/soapbox/features/ui/components/actions_modal.js

97 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { FormattedMessage, injectIntl } from 'react-intl';
import spring from 'react-motion/lib/spring';
2020-03-27 13:59:38 -07:00
import StatusContent from '../../../components/status_content';
import Avatar from '../../../components/avatar';
import RelativeTimestamp from '../../../components/relative_timestamp';
import DisplayName from '../../../components/display_name';
import Icon from '../../../components/icon';
import Button from '../../../components/button';
import Motion from '../util/optional_motion';
2020-03-27 13:59:38 -07:00
import classNames from 'classnames';
export default @injectIntl
class ActionsModal extends ImmutablePureComponent {
2020-03-27 13:59:38 -07:00
static propTypes = {
status: ImmutablePropTypes.map,
actions: PropTypes.array,
onClick: PropTypes.func,
onClose: PropTypes.func.isRequired,
2020-03-27 13:59:38 -07:00
};
renderAction = (action, i) => {
if (action === null) {
return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
}
const { icon = null, text, meta = null, active = false, href = '#', isLogout, destructive } = action;
2020-03-27 13:59:38 -07:00
return (
<li key={`${text}-${i}`}>
<a
href={href}
rel='noopener'
onClick={this.props.onClick}
data-index={i}
className={classNames({ active, destructive })}
2020-03-27 13:59:38 -07:00
data-method={isLogout ? 'delete' : null}
>
{icon && <Icon title={text} src={icon} role='presentation' tabIndex='-1' inverted />}
2020-03-27 13:59:38 -07:00
<div>
<div className={classNames({ 'actions-modal__item-label': !!meta })}>{text}</div>
<div>{meta}</div>
</div>
</a>
</li>
);
}
render() {
const { actions, onClose } = this.props;
2020-03-27 13:59:38 -07:00
const status = this.props.status && (
<div className='status light'>
<div className='boost-modal__status-header'>
<div className='boost-modal__status-time'>
<a href={this.props.status.get('url')} className='status__relative-time' target='_blank' rel='noopener'>
<RelativeTimestamp timestamp={this.props.status.get('created_at')} />
</a>
</div>
<a href={`/@${this.props.status.getIn(['account', 'acct'])}`} className='status__display-name'>
<div className='status__avatar'>
<Avatar account={this.props.status.get('account')} size={48} />
</div>
<DisplayName account={this.props.status.get('account')} />
</a>
</div>
<StatusContent status={this.props.status} />
</div>
);
return (
<Motion defaultStyle={{ top: 100 }} style={{ top: spring(0) }}>
{({ top }) => (
<div className='modal-root__modal actions-modal' style={{ top: `${top}%` }}>
{status}
2020-03-27 13:59:38 -07:00
<ul className={classNames({ 'with-status': !!status })}>
{actions && actions.map(this.renderAction)}
<Button className='actions-modal__close-button' onClick={onClose}>
<FormattedMessage id='lightbox.close' defaultMessage='Close' />
</Button>
</ul>
</div>
)}
</Motion>
2020-03-27 13:59:38 -07:00
);
}
}