The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

65 lines
1.7 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import ImmutablePureComponent from 'react-immutable-pure-component';
  4. import Permalink from '../../../components/permalink';
  5. import { displayMedia } from '../../../initial_state';
  6. import Icon from 'mastodon/components/icon';
  7. export default class MediaItem extends ImmutablePureComponent {
  8. static propTypes = {
  9. media: ImmutablePropTypes.map.isRequired,
  10. };
  11. state = {
  12. visible: displayMedia !== 'hide_all' && !this.props.media.getIn(['status', 'sensitive']) || displayMedia === 'show_all',
  13. };
  14. handleClick = () => {
  15. if (!this.state.visible) {
  16. this.setState({ visible: true });
  17. return true;
  18. }
  19. return false;
  20. }
  21. render () {
  22. const { media } = this.props;
  23. const { visible } = this.state;
  24. const status = media.get('status');
  25. const focusX = media.getIn(['meta', 'focus', 'x']);
  26. const focusY = media.getIn(['meta', 'focus', 'y']);
  27. const x = ((focusX / 2) + .5) * 100;
  28. const y = ((focusY / -2) + .5) * 100;
  29. const style = {};
  30. let label, icon;
  31. if (media.get('type') === 'gifv') {
  32. label = <span className='media-gallery__gifv__label'>GIF</span>;
  33. }
  34. if (visible) {
  35. style.backgroundImage = `url(${media.get('preview_url')})`;
  36. style.backgroundPosition = `${x}% ${y}%`;
  37. } else {
  38. icon = (
  39. <span className='account-gallery__item__icons'>
  40. <Icon id='eye-slash' />
  41. </span>
  42. );
  43. }
  44. return (
  45. <div className='account-gallery__item'>
  46. <Permalink to={`/statuses/${status.get('id')}`} href={status.get('url')} style={style} onInterceptClick={this.handleClick}>
  47. {icon}
  48. {label}
  49. </Permalink>
  50. </div>
  51. );
  52. }
  53. }