闭社主体 forked from https://github.com/tootsuite/mastodon
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.

86 lines
2.9 KiB

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