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.

79 lines
2.6 KiB

  1. // Package imports //
  2. import React from 'react';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import PropTypes from 'prop-types';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. // Mastodon imports //
  7. import IconButton from '../../../../mastodon/components/icon_button';
  8. // Our imports //
  9. import StatusGalleryItem from './item';
  10. const messages = defineMessages({
  11. toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' },
  12. });
  13. @injectIntl
  14. export default class StatusGallery extends React.PureComponent {
  15. static propTypes = {
  16. sensitive: PropTypes.bool,
  17. media: ImmutablePropTypes.list.isRequired,
  18. letterbox: PropTypes.bool,
  19. fullwidth: PropTypes.bool,
  20. height: PropTypes.number.isRequired,
  21. onOpenMedia: PropTypes.func.isRequired,
  22. intl: PropTypes.object.isRequired,
  23. autoPlayGif: PropTypes.bool.isRequired,
  24. };
  25. state = {
  26. visible: !this.props.sensitive,
  27. };
  28. handleOpen = () => {
  29. this.setState({ visible: !this.state.visible });
  30. }
  31. handleClick = (index) => {
  32. this.props.onOpenMedia(this.props.media, index);
  33. }
  34. render () {
  35. const { media, intl, sensitive, letterbox, fullwidth } = this.props;
  36. let children;
  37. if (!this.state.visible) {
  38. let warning;
  39. if (sensitive) {
  40. warning = <FormattedMessage id='status.sensitive_warning' defaultMessage='Sensitive content' />;
  41. } else {
  42. warning = <FormattedMessage id='status.media_hidden' defaultMessage='Media hidden' />;
  43. }
  44. children = (
  45. <div role='button' tabIndex='0' className='media-spoiler' onClick={this.handleOpen}>
  46. <span className='media-spoiler__warning'>{warning}</span>
  47. <span className='media-spoiler__trigger'><FormattedMessage id='status.sensitive_toggle' defaultMessage='Click to view' /></span>
  48. </div>
  49. );
  50. } else {
  51. const size = media.take(4).size;
  52. children = media.take(4).map((attachment, i) => <StatusGalleryItem key={attachment.get('id')} onClick={this.handleClick} attachment={attachment} autoPlayGif={this.props.autoPlayGif} index={i} size={size} letterbox={letterbox} />);
  53. }
  54. return (
  55. <div className={`media-gallery ${fullwidth ? 'full-width' : ''}`} style={{ height: `${this.props.height}px` }}>
  56. <div className={`spoiler-button ${this.state.visible ? 'spoiler-button--visible' : ''}`}>
  57. <IconButton title={intl.formatMessage(messages.toggle_visible)} icon={this.state.visible ? 'eye' : 'eye-slash'} overlay onClick={this.handleOpen} />
  58. </div>
  59. {children}
  60. </div>
  61. );
  62. }
  63. }