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.

96 lines
2.2 KiB

  1. // Package imports.
  2. import PropTypes from 'prop-types';
  3. import React from 'react';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import { defineMessages } from 'react-intl';
  6. // Components.
  7. import AccountContainer from 'flavours/glitch/containers/account_container';
  8. import IconButton from 'flavours/glitch/components/icon_button';
  9. import AttachmentList from 'flavours/glitch/components/attachment_list';
  10. // Utils.
  11. import { assignHandlers } from 'flavours/glitch/util/react_helpers';
  12. import { isRtl } from 'flavours/glitch/util/rtl';
  13. // Messages.
  14. const messages = defineMessages({
  15. cancel: {
  16. defaultMessage: 'Cancel',
  17. id: 'reply_indicator.cancel',
  18. },
  19. });
  20. // Handlers.
  21. const handlers = {
  22. // Handles a click on the "close" button.
  23. handleClick () {
  24. const { onCancel } = this.props;
  25. if (onCancel) {
  26. onCancel();
  27. }
  28. },
  29. };
  30. // The component.
  31. export default class ComposerReply extends React.PureComponent {
  32. // Constructor.
  33. constructor (props) {
  34. super(props);
  35. assignHandlers(this, handlers);
  36. }
  37. // Rendering.
  38. render () {
  39. const { handleClick } = this.handlers;
  40. const {
  41. status,
  42. intl,
  43. } = this.props;
  44. const account = status.get('account');
  45. const content = status.get('content');
  46. const attachments = status.get('media_attachments');
  47. // The result.
  48. return (
  49. <article className='composer--reply'>
  50. <header>
  51. <IconButton
  52. className='cancel'
  53. icon='times'
  54. onClick={handleClick}
  55. title={intl.formatMessage(messages.cancel)}
  56. inverted
  57. />
  58. {account && (
  59. <AccountContainer
  60. id={account}
  61. small
  62. />
  63. )}
  64. </header>
  65. <div
  66. className='content'
  67. dangerouslySetInnerHTML={{ __html: content || '' }}
  68. style={{ direction: isRtl(content) ? 'rtl' : 'ltr' }}
  69. />
  70. {attachments.size > 0 && (
  71. <AttachmentList
  72. compact
  73. media={attachments}
  74. />
  75. )}
  76. </article>
  77. );
  78. }
  79. }
  80. ComposerReply.propTypes = {
  81. status: ImmutablePropTypes.map.isRequired,
  82. intl: PropTypes.object.isRequired,
  83. onCancel: PropTypes.func,
  84. };