2017-01-16 13:04:02 +02:00
|
|
|
import { connect } from 'react-redux';
|
2017-02-05 03:48:11 +02:00
|
|
|
import {
|
|
|
|
closeModal,
|
|
|
|
decreaseIndexInModal,
|
|
|
|
increaseIndexInModal
|
|
|
|
} from '../../../actions/modal';
|
2017-01-16 13:04:02 +02:00
|
|
|
import Lightbox from '../../../components/lightbox';
|
|
|
|
import ImageLoader from 'react-imageloader';
|
|
|
|
import LoadingIndicator from '../../../components/loading_indicator';
|
2017-01-23 22:40:48 +02:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2017-02-05 03:48:11 +02:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-03-04 23:17:10 +02:00
|
|
|
import ExtendedVideoPlayer from '../../../components/extended_video_player';
|
2016-10-24 19:07:40 +03:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-02-05 03:48:11 +02:00
|
|
|
media: state.getIn(['modal', 'media']),
|
|
|
|
index: state.getIn(['modal', 'index']),
|
2016-10-24 19:07:40 +03:00
|
|
|
isVisible: state.getIn(['modal', 'open'])
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
onCloseClicked () {
|
|
|
|
dispatch(closeModal());
|
|
|
|
},
|
|
|
|
|
|
|
|
onOverlayClicked () {
|
|
|
|
dispatch(closeModal());
|
2017-02-05 03:48:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onNextClicked () {
|
|
|
|
dispatch(increaseIndexInModal());
|
|
|
|
},
|
|
|
|
|
|
|
|
onPrevClicked () {
|
|
|
|
dispatch(decreaseIndexInModal());
|
2016-10-24 19:07:40 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-07 19:23:36 +02:00
|
|
|
const imageStyle = {
|
|
|
|
display: 'block',
|
2016-11-11 00:21:24 +02:00
|
|
|
maxWidth: '80vw',
|
|
|
|
maxHeight: '80vh'
|
2016-10-24 19:07:40 +03:00
|
|
|
};
|
|
|
|
|
2017-01-16 20:36:32 +02:00
|
|
|
const loadingStyle = {
|
|
|
|
width: '400px',
|
|
|
|
paddingBottom: '120px'
|
|
|
|
};
|
|
|
|
|
|
|
|
const preloader = () => (
|
2017-02-10 18:30:06 +02:00
|
|
|
<div className='modal-container--preloader' style={loadingStyle}>
|
2017-01-16 20:36:32 +02:00
|
|
|
<LoadingIndicator />
|
|
|
|
</div>
|
|
|
|
);
|
2017-01-16 13:04:02 +02:00
|
|
|
|
2017-02-05 03:48:11 +02:00
|
|
|
const leftNavStyle = {
|
|
|
|
position: 'absolute',
|
|
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
padding: '30px 15px',
|
|
|
|
cursor: 'pointer',
|
|
|
|
fontSize: '24px',
|
|
|
|
top: '0',
|
|
|
|
left: '-61px',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
height: '100%',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center'
|
|
|
|
};
|
|
|
|
|
|
|
|
const rightNavStyle = {
|
|
|
|
position: 'absolute',
|
|
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
padding: '30px 15px',
|
|
|
|
cursor: 'pointer',
|
|
|
|
fontSize: '24px',
|
|
|
|
top: '0',
|
|
|
|
right: '-61px',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
height: '100%',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center'
|
|
|
|
};
|
|
|
|
|
2016-10-24 19:07:40 +03:00
|
|
|
const Modal = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
2017-02-05 03:48:11 +02:00
|
|
|
media: ImmutablePropTypes.list,
|
|
|
|
index: React.PropTypes.number.isRequired,
|
2016-10-24 19:07:40 +03:00
|
|
|
isVisible: React.PropTypes.bool,
|
|
|
|
onCloseClicked: React.PropTypes.func,
|
2017-02-05 03:48:11 +02:00
|
|
|
onOverlayClicked: React.PropTypes.func,
|
|
|
|
onNextClicked: React.PropTypes.func,
|
|
|
|
onPrevClicked: React.PropTypes.func
|
2016-10-24 19:07:40 +03:00
|
|
|
},
|
|
|
|
|
2017-01-23 22:40:48 +02:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2017-02-05 03:48:11 +02:00
|
|
|
handleNextClick () {
|
|
|
|
this.props.onNextClicked();
|
|
|
|
},
|
|
|
|
|
|
|
|
handlePrevClick () {
|
|
|
|
this.props.onPrevClicked();
|
|
|
|
},
|
|
|
|
|
2017-02-05 04:01:23 +02:00
|
|
|
componentDidMount () {
|
|
|
|
this._listener = e => {
|
|
|
|
if (!this.props.isVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(e.key) {
|
|
|
|
case 'ArrowLeft':
|
|
|
|
this.props.onPrevClicked();
|
|
|
|
break;
|
|
|
|
case 'ArrowRight':
|
|
|
|
this.props.onNextClicked();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('keyup', this._listener);
|
|
|
|
},
|
|
|
|
|
2017-02-05 04:19:04 +02:00
|
|
|
componentWillUnmount () {
|
2017-02-05 04:01:23 +02:00
|
|
|
window.removeEventListener('keyup', this._listener);
|
|
|
|
},
|
|
|
|
|
2016-10-24 19:07:40 +03:00
|
|
|
render () {
|
2017-02-05 03:48:11 +02:00
|
|
|
const { media, index, ...other } = this.props;
|
|
|
|
|
|
|
|
if (!media) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-03-04 23:17:10 +02:00
|
|
|
const attachment = media.get(index);
|
|
|
|
const url = attachment.get('url');
|
2017-02-05 03:48:11 +02:00
|
|
|
|
2017-03-04 23:17:10 +02:00
|
|
|
let leftNav, rightNav, content;
|
2017-02-05 03:48:11 +02:00
|
|
|
|
2017-03-04 23:17:10 +02:00
|
|
|
leftNav = rightNav = content = '';
|
2017-02-05 03:48:11 +02:00
|
|
|
|
2017-02-26 02:23:44 +02:00
|
|
|
if (media.size > 1) {
|
|
|
|
leftNav = <div style={leftNavStyle} className='modal-container--nav' onClick={this.handlePrevClick}><i className='fa fa-fw fa-chevron-left' /></div>;
|
2017-02-10 18:30:06 +02:00
|
|
|
rightNav = <div style={rightNavStyle} className='modal-container--nav' onClick={this.handleNextClick}><i className='fa fa-fw fa-chevron-right' /></div>;
|
2017-02-05 03:48:11 +02:00
|
|
|
}
|
2016-10-24 19:07:40 +03:00
|
|
|
|
2017-03-04 23:17:10 +02:00
|
|
|
if (attachment.get('type') === 'image') {
|
|
|
|
content = (
|
2017-01-16 13:04:02 +02:00
|
|
|
<ImageLoader
|
|
|
|
src={url}
|
|
|
|
preloader={preloader}
|
|
|
|
imgProps={{ style: imageStyle }}
|
|
|
|
/>
|
2017-03-04 23:17:10 +02:00
|
|
|
);
|
|
|
|
} else if (attachment.get('type') === 'gifv') {
|
|
|
|
content = <ExtendedVideoPlayer src={url} />;
|
|
|
|
}
|
2017-02-05 03:48:11 +02:00
|
|
|
|
2017-03-04 23:17:10 +02:00
|
|
|
return (
|
|
|
|
<Lightbox {...other}>
|
|
|
|
{leftNav}
|
|
|
|
{content}
|
2017-02-05 03:48:11 +02:00
|
|
|
{rightNav}
|
2016-11-07 19:23:36 +02:00
|
|
|
</Lightbox>
|
2016-10-24 19:07:40 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Modal);
|