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

100% Statements 16/16
100% Branches 0/0
100% Functions 5/5
100% Lines 15/15
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 441x 1x 1x 1x 1x       3x   3x       1x       3x 6x   3x                 1x     3x   3x         1x      
import React, {Component} from 'react';
import {connect} from "react-redux";
import PropTypes from 'prop-types';
import ContentsPreviewHeaderView from "./contents-preview-header-view";
import ContentsPreviewDetailView from "./contents-preview-detail-view";
 
class ContentsPreview extends Component {
    constructor(props) {
        super(props);
 
        this.onClickClose = this.onClickClose.bind(this);
    }
 
    onClickClose() {
        this.props.history.goBack();
    }
 
    render() {
        const {selectedId, contents} = this.props;
        const contentsItem = contents.find(contentsItem => contentsItem.id === selectedId);
 
        return (
            <div>
                <ContentsPreviewHeaderView type={contentsItem.type} name={contentsItem.name} onClickClose={this.onClickClose}/>
                <ContentsPreviewDetailView contents={contentsItem} />
            </div>
        );
    }
}
 
const mapStateToProps = (state) => {
    const {
        contents: {selectedId, contents}
    } = state;
 
    return {selectedId, contents};
};
 
export default connect(mapStateToProps)(ContentsPreview);
 
ContentsPreview.propTypes = {
    selectedId: PropTypes.string.isRequired,
    contents: PropTypes.array.isRequired,
};