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