All files / nexshop-web-contents/src/component/preview/playlist playlist-preview.js

100% Statements 21/21
100% Branches 2/2
100% Functions 5/5
100% Lines 21/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641x 1x 1x 1x 1x 1x 1x 1x       9x   9x       2x 2x 2x         9x   9x                                           1x 9x   9x       1x 9x   9x          
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from "redux";
import {DiscardRefresh} from 'nexshop-web-alert';
import {previewActions} from "nexshop-web-store";
import PlaylistPreviewDetailView from "./playlist-preview-detail-view";
import PlaylistPreviewHeaderView from "./playlist-preview-header-view";
import PlaylistPreviewListView from "./playlist-preview-list-view";
 
class PlaylistPreview extends Component {
    constructor(props) {
        super(props);
 
        this.onClickClose = this.onClickClose.bind(this);
    }
 
    onClickClose() {
        this.props.history.goBack();
        this.props.actions.selectPreviewItem(0);
        this.props.actions.deletePreviewPreviousIndex();
    }
 
    render() {
        let {name, contentItems, selectedPreviewItemIndex, selectedPreviewPreviousItemIndex, previewWindowSize, resolution,
            actions: {selectPreviewItem}} = this.props;
 
        return (
            <div className="preview">
                <PlaylistPreviewHeaderView name={name} onClickClose={this.onClickClose}/>
                {
                    this.props.name &&
                    <div className="preview-body">
                        <PlaylistPreviewListView contentItems={contentItems}
                                                 selectedPreviewItemIndex={selectedPreviewItemIndex}
                                                 onSelectPreviewItem={selectPreviewItem}/>
                        <PlaylistPreviewDetailView contentItem={contentItems[selectedPreviewItemIndex]}
                                                   previousContentItem={contentItems[selectedPreviewPreviousItemIndex]}
                                                   previewWindowSize={previewWindowSize}
                                                   resolution={resolution}
                        />
                    </div>
                }
                <DiscardRefresh/>
            </div>
        );
    }
}
 
const mapStateToProps = (state) => {
    const {preview: {name, contentItems, selectedPreviewItemIndex, selectedPreviewPreviousItemIndex, previewWindowSize, resolution}} = state;
 
    return {name, contentItems, selectedPreviewItemIndex, selectedPreviewPreviousItemIndex,
        previewWindowSize, resolution};
};
 
const mapDispatchToProps = (dispatch) => {
    const {selectPreviewItem, deletePreviewPreviousIndex} = previewActions;
 
    return {
        actions: bindActionCreators({selectPreviewItem, deletePreviewPreviousIndex}, dispatch)
    }
};
 
export default connect(mapStateToProps, mapDispatchToProps)(PlaylistPreview);