gab-social/app/javascript/gabsocial/components/modal/boost_modal.js

106 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { defineMessages, injectIntl } from 'react-intl';
2020-02-24 23:25:55 +00:00
import Button from '../button';
import StatusContent from '../status_content';
import Avatar from '../avatar';
import RelativeTimestamp from '../relative_timestamp';
import DisplayName from '../display_name';
import Icon from '../icon';
2019-07-02 08:10:25 +01:00
const messages = defineMessages({
2020-03-04 22:50:15 +00:00
cancel_repost: { id: 'status.cancel_repost_private', defaultMessage: 'Un-repost' },
repost: { id: 'status.repost', defaultMessage: 'Repost' },
combo: { id: 'boost_modal.combo', defaultMessage: 'You can press {combo} to skip this next time' },
2019-07-02 08:10:25 +01:00
});
2020-02-25 16:04:44 +00:00
export default
@injectIntl
2019-07-02 08:10:25 +01:00
class BoostModal extends ImmutablePureComponent {
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
status: ImmutablePropTypes.map.isRequired,
2020-03-04 22:26:01 +00:00
onRepost: PropTypes.func.isRequired,
2019-07-02 08:10:25 +01:00
onClose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
componentDidMount() {
this.button.focus();
}
2020-03-04 22:26:01 +00:00
handleRepost = () => {
this.props.onRepost(this.props.status);
2019-07-02 08:10:25 +01:00
this.props.onClose();
}
handleAccountClick = (e) => {
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault();
this.props.onClose();
this.context.router.history.push(`/${this.props.status.getIn(['account', 'acct'])}`);
}
}
handleStatusClick = (e) => {
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault();
this.props.onClose();
this.context.router.history.push(`/${this.props.status.getIn(['account', 'acct'])}/posts/${this.props.status.get('url')}`);
}
}
setRef = (c) => {
this.button = c;
}
render () {
const { status, intl } = this.props;
2020-03-04 22:50:15 +00:00
const buttonText = status.get('reblogged') ? messages.cancel_repost : messages.repost;
2019-07-02 08:10:25 +01:00
const statusUrl = `/${status.getIn(['account', 'acct'])}/posts/${status.get('url')}`;
return (
<div className='modal-root__modal boost-modal'>
<div className='boost-modal__container'>
<div className='status light'>
<div className='boost-modal__status-header'>
<div className='boost-modal__status-time'>
<a onClick={this.handleStatusClick} href={statusUrl} className='status__relative-time'>
<RelativeTimestamp timestamp={status.get('created_at')} />
</a>
</div>
<a onClick={this.handleAccountClick} href={`/${status.getIn(['account', 'acct'])}`} className='status__display-name'>
<div className='status__avatar'>
<Avatar account={status.get('account')} size={48} />
</div>
<DisplayName account={status.get('account')} />
</a>
</div>
<StatusContent status={status} />
</div>
</div>
<div className='boost-modal__action-bar'>
<div>
{intl.formatMessage(messages.combo, {
values: {
combo: <span>Shift + <Icon id='retweet' /></span>
}
})}
</div>
2020-03-04 22:26:01 +00:00
<Button text={intl.formatMessage(buttonText)} onClick={this.handleRepost} ref={this.setRef} />
2019-07-02 08:10:25 +01:00
</div>
</div>
);
}
}