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.

84 lines
2.8 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 Button from 'flavours/glitch/components/button';
  6. import StatusContent from 'flavours/glitch/components/status_content';
  7. import Avatar from 'flavours/glitch/components/avatar';
  8. import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp';
  9. import DisplayName from 'flavours/glitch/components/display_name';
  10. import ImmutablePureComponent from 'react-immutable-pure-component';
  11. const messages = defineMessages({
  12. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  13. });
  14. @injectIntl
  15. export default 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.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
  37. }
  38. }
  39. setRef = (c) => {
  40. this.button = c;
  41. }
  42. render () {
  43. const { status, intl } = 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 account={status.get('account')} 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. }