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.

68 lines
1.4 KiB

  1. import { connect } from 'react-redux';
  2. import { closeModal } from '../../../actions/modal';
  3. import Lightbox from '../../../components/lightbox';
  4. import ImageLoader from 'react-imageloader';
  5. import LoadingIndicator from '../../../components/loading_indicator';
  6. import PureRenderMixin from 'react-addons-pure-render-mixin';
  7. const mapStateToProps = state => ({
  8. url: state.getIn(['modal', 'url']),
  9. isVisible: state.getIn(['modal', 'open'])
  10. });
  11. const mapDispatchToProps = dispatch => ({
  12. onCloseClicked () {
  13. dispatch(closeModal());
  14. },
  15. onOverlayClicked () {
  16. dispatch(closeModal());
  17. }
  18. });
  19. const imageStyle = {
  20. display: 'block',
  21. maxWidth: '80vw',
  22. maxHeight: '80vh'
  23. };
  24. const loadingStyle = {
  25. background: '#373b4a',
  26. width: '400px',
  27. paddingBottom: '120px'
  28. };
  29. const preloader = () => (
  30. <div style={loadingStyle}>
  31. <LoadingIndicator />
  32. </div>
  33. );
  34. const Modal = React.createClass({
  35. propTypes: {
  36. url: React.PropTypes.string,
  37. isVisible: React.PropTypes.bool,
  38. onCloseClicked: React.PropTypes.func,
  39. onOverlayClicked: React.PropTypes.func
  40. },
  41. mixins: [PureRenderMixin],
  42. render () {
  43. const { url, ...other } = this.props;
  44. return (
  45. <Lightbox {...other}>
  46. <ImageLoader
  47. src={url}
  48. preloader={preloader}
  49. imgProps={{ style: imageStyle }}
  50. />
  51. </Lightbox>
  52. );
  53. }
  54. });
  55. export default connect(mapStateToProps, mapDispatchToProps)(Modal);