2017-01-16 20:04:02 +09:00
|
|
|
import { connect } from 'react-redux';
|
2017-02-05 10:48:11 +09:00
|
|
|
import {
|
|
|
|
closeModal,
|
|
|
|
decreaseIndexInModal,
|
|
|
|
increaseIndexInModal
|
|
|
|
} from '../../../actions/modal';
|
2017-01-16 20:04:02 +09:00
|
|
|
import Lightbox from '../../../components/lightbox';
|
|
|
|
import ImageLoader from 'react-imageloader';
|
|
|
|
import LoadingIndicator from '../../../components/loading_indicator';
|
2017-01-24 05:40:48 +09:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2017-02-05 10:48:11 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-10-25 01:07:40 +09:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-02-05 10:48:11 +09:00
|
|
|
media: state.getIn(['modal', 'media']),
|
|
|
|
index: state.getIn(['modal', 'index']),
|
2016-10-25 01:07:40 +09:00
|
|
|
isVisible: state.getIn(['modal', 'open'])
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
onCloseClicked () {
|
|
|
|
dispatch(closeModal());
|
|
|
|
},
|
|
|
|
|
|
|
|
onOverlayClicked () {
|
|
|
|
dispatch(closeModal());
|
2017-02-05 10:48:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
onNextClicked () {
|
|
|
|
dispatch(increaseIndexInModal());
|
|
|
|
},
|
|
|
|
|
|
|
|
onPrevClicked () {
|
|
|
|
dispatch(decreaseIndexInModal());
|
2016-10-25 01:07:40 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-08 02:23:36 +09:00
|
|
|
const imageStyle = {
|
|
|
|
display: 'block',
|
2016-11-11 07:21:24 +09:00
|
|
|
maxWidth: '80vw',
|
|
|
|
maxHeight: '80vh'
|
2016-10-25 01:07:40 +09:00
|
|
|
};
|
|
|
|
|
2017-01-17 03:36:32 +09:00
|
|
|
const loadingStyle = {
|
|
|
|
background: '#373b4a',
|
|
|
|
width: '400px',
|
|
|
|
paddingBottom: '120px'
|
|
|
|
};
|
|
|
|
|
|
|
|
const preloader = () => (
|
|
|
|
<div style={loadingStyle}>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</div>
|
|
|
|
);
|
2017-01-16 20:04:02 +09:00
|
|
|
|
2017-02-05 10:48:11 +09:00
|
|
|
const leftNavStyle = {
|
|
|
|
position: 'absolute',
|
|
|
|
background: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
padding: '30px 15px',
|
|
|
|
cursor: 'pointer',
|
|
|
|
color: '#fff',
|
|
|
|
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',
|
|
|
|
color: '#fff',
|
|
|
|
fontSize: '24px',
|
|
|
|
top: '0',
|
|
|
|
right: '-61px',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
height: '100%',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center'
|
|
|
|
};
|
|
|
|
|
2016-10-25 01:07:40 +09:00
|
|
|
const Modal = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
2017-02-05 10:48:11 +09:00
|
|
|
media: ImmutablePropTypes.list,
|
|
|
|
index: React.PropTypes.number.isRequired,
|
2016-10-25 01:07:40 +09:00
|
|
|
isVisible: React.PropTypes.bool,
|
|
|
|
onCloseClicked: React.PropTypes.func,
|
2017-02-05 10:48:11 +09:00
|
|
|
onOverlayClicked: React.PropTypes.func,
|
|
|
|
onNextClicked: React.PropTypes.func,
|
|
|
|
onPrevClicked: React.PropTypes.func
|
2016-10-25 01:07:40 +09:00
|
|
|
},
|
|
|
|
|
2017-01-24 05:40:48 +09:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2017-02-05 10:48:11 +09:00
|
|
|
handleNextClick () {
|
|
|
|
this.props.onNextClicked();
|
|
|
|
},
|
|
|
|
|
|
|
|
handlePrevClick () {
|
|
|
|
this.props.onPrevClicked();
|
|
|
|
},
|
|
|
|
|
2016-10-25 01:07:40 +09:00
|
|
|
render () {
|
2017-02-05 10:48:11 +09:00
|
|
|
const { media, index, ...other } = this.props;
|
|
|
|
|
|
|
|
if (!media) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = media.get(index).get('url');
|
|
|
|
const hasLeft = index > 0;
|
|
|
|
const hasRight = index + 1 < media.size;
|
|
|
|
|
|
|
|
let leftNav, rightNav;
|
|
|
|
|
|
|
|
leftNav = rightNav = '';
|
|
|
|
|
|
|
|
if (hasLeft) {
|
|
|
|
leftNav = <div style={leftNavStyle} onClick={this.handlePrevClick}><i className='fa fa-fw fa-chevron-left' /></div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasRight) {
|
|
|
|
rightNav = <div style={rightNavStyle} onClick={this.handleNextClick}><i className='fa fa-fw fa-chevron-right' /></div>;
|
|
|
|
}
|
2016-10-25 01:07:40 +09:00
|
|
|
|
|
|
|
return (
|
2016-11-08 02:23:36 +09:00
|
|
|
<Lightbox {...other}>
|
2017-02-05 10:48:11 +09:00
|
|
|
{leftNav}
|
|
|
|
|
2017-01-16 20:04:02 +09:00
|
|
|
<ImageLoader
|
|
|
|
src={url}
|
|
|
|
preloader={preloader}
|
|
|
|
imgProps={{ style: imageStyle }}
|
|
|
|
/>
|
2017-02-05 10:48:11 +09:00
|
|
|
|
|
|
|
{rightNav}
|
2016-11-08 02:23:36 +09:00
|
|
|
</Lightbox>
|
2016-10-25 01:07:40 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Modal);
|