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.

124 lines
3.5 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import StatusContent from 'flavours/glitch/components/status_content';
  6. import Avatar from 'flavours/glitch/components/avatar';
  7. import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp';
  8. import DisplayName from 'flavours/glitch/components/display_name';
  9. import classNames from 'classnames';
  10. import Icon from 'flavours/glitch/components/icon';
  11. import Link from 'flavours/glitch/components/link';
  12. import Toggle from 'react-toggle';
  13. export default class ActionsModal extends ImmutablePureComponent {
  14. static propTypes = {
  15. status: ImmutablePropTypes.map,
  16. actions: PropTypes.arrayOf(PropTypes.shape({
  17. active: PropTypes.bool,
  18. href: PropTypes.string,
  19. icon: PropTypes.string,
  20. meta: PropTypes.node,
  21. name: PropTypes.string,
  22. on: PropTypes.bool,
  23. onPassiveClick: PropTypes.func,
  24. text: PropTypes.node,
  25. })),
  26. };
  27. renderAction = (action, i) => {
  28. if (action === null) {
  29. return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
  30. }
  31. const {
  32. active,
  33. href,
  34. icon,
  35. meta,
  36. name,
  37. on,
  38. onClick,
  39. onPassiveClick,
  40. text,
  41. } = action;
  42. return (
  43. <li key={name || i}>
  44. <Link
  45. className={classNames('link', { active })}
  46. href={href}
  47. onClick={on !== null && typeof on !== 'undefined' && onPassiveClick || onClick}
  48. role={onClick ? 'button' : null}
  49. >
  50. {function () {
  51. // We render a `<Toggle>` if we were provided an `on`
  52. // property, and otherwise show an `<Icon>` if available.
  53. switch (true) {
  54. case on !== null && typeof on !== 'undefined':
  55. return (
  56. <Toggle
  57. checked={on}
  58. onChange={onPassiveClick || onClick}
  59. />
  60. );
  61. case !!icon:
  62. return (
  63. <Icon
  64. className='icon'
  65. fullwidth
  66. icon={icon}
  67. />
  68. );
  69. default:
  70. return null;
  71. }
  72. }()}
  73. {meta ? (
  74. <div>
  75. <strong>{text}</strong>
  76. {meta}
  77. </div>
  78. ) : <div>{text}</div>}
  79. </Link>
  80. </li>
  81. );
  82. }
  83. render () {
  84. const status = this.props.status && (
  85. <div className='status light'>
  86. <div className='boost-modal__status-header'>
  87. <div className='boost-modal__status-time'>
  88. <a href={this.props.status.get('url')} className='status__relative-time' target='_blank' rel='noopener'>
  89. <RelativeTimestamp timestamp={this.props.status.get('created_at')} />
  90. </a>
  91. </div>
  92. <a href={this.props.status.getIn(['account', 'url'])} className='status__display-name'>
  93. <div className='status__avatar'>
  94. <Avatar account={this.props.status.get('account')} size={48} />
  95. </div>
  96. <DisplayName account={this.props.status.get('account')} />
  97. </a>
  98. </div>
  99. <StatusContent status={this.props.status} />
  100. </div>
  101. );
  102. return (
  103. <div className='modal-root__modal actions-modal'>
  104. {status}
  105. <ul>
  106. {this.props.actions.map(this.renderAction)}
  107. </ul>
  108. </div>
  109. );
  110. }
  111. }