boost_modal.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  5. import Button from '../../../components/button';
  6. import StatusContent from '../../../components/status_content';
  7. import Avatar from '../../../components/avatar';
  8. import RelativeTimestamp from '../../../components/relative_timestamp';
  9. import DisplayName from '../../../components/display_name';
  10. import ImmutablePureComponent from 'react-immutable-pure-component';
  11. import Icon from 'mastodon/components/icon';
  12. const messages = defineMessages({
  13. cancel_reblog: { id: 'status.cancel_reblog_private', defaultMessage: 'Unboost' },
  14. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  15. });
  16. export default @injectIntl
  17. class BoostModal extends ImmutablePureComponent {
  18. static contextTypes = {
  19. router: PropTypes.object,
  20. };
  21. static propTypes = {
  22. status: ImmutablePropTypes.map.isRequired,
  23. onReblog: PropTypes.func.isRequired,
  24. onClose: PropTypes.func.isRequired,
  25. intl: PropTypes.object.isRequired,
  26. };
  27. componentDidMount() {
  28. this.button.focus();
  29. }
  30. handleReblog = () => {
  31. this.props.onReblog(this.props.status);
  32. this.props.onClose();
  33. }
  34. handleAccountClick = (e) => {
  35. if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
  36. e.preventDefault();
  37. this.props.onClose();
  38. this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  39. }
  40. }
  41. setRef = (c) => {
  42. this.button = c;
  43. }
  44. render () {
  45. const { status, intl } = this.props;
  46. const buttonText = status.get('reblogged') ? messages.cancel_reblog : messages.reblog;
  47. return (
  48. <div className='modal-root__modal boost-modal'>
  49. <div className='boost-modal__container'>
  50. <div className='status light'>
  51. <div className='boost-modal__status-header'>
  52. <div className='boost-modal__status-time'>
  53. <a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
  54. </div>
  55. <a onClick={this.handleAccountClick} href={status.getIn(['account', 'url'])} className='status__display-name'>
  56. <div className='status__avatar'>
  57. <Avatar account={status.get('account')} size={48} />
  58. </div>
  59. <DisplayName account={status.get('account')} />
  60. </a>
  61. </div>
  62. <StatusContent status={status} />
  63. </div>
  64. </div>
  65. <div className='boost-modal__action-bar'>
  66. <div><FormattedMessage id='boost_modal.combo' defaultMessage='You can press {combo} to skip this next time' values={{ combo: <span>Shift + <Icon id='retweet' /></span> }} /></div>
  67. <Button text={intl.formatMessage(buttonText)} onClick={this.handleReblog} ref={this.setRef} />
  68. </div>
  69. </div>
  70. );
  71. }
  72. }