2018-11-07 18:16:50 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-12-07 14:08:32 +02:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
2018-05-27 09:37:46 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2018-04-06 14:51:52 +01:00
|
|
|
|
2018-12-07 14:08:32 +02:00
|
|
|
import { previewMounted } from '../redux';
|
|
|
|
|
2018-04-06 14:51:52 +01:00
|
|
|
import './preview.css';
|
|
|
|
|
|
|
|
const mainId = 'fcc-main-frame';
|
|
|
|
|
2018-12-07 14:08:32 +02:00
|
|
|
const mapDispatchToProps = dispatch =>
|
|
|
|
bindActionCreators(
|
|
|
|
{
|
|
|
|
previewMounted
|
|
|
|
},
|
|
|
|
dispatch
|
|
|
|
);
|
|
|
|
|
2018-05-27 09:37:46 +01:00
|
|
|
const propTypes = {
|
|
|
|
className: PropTypes.string,
|
2018-12-07 14:08:32 +02:00
|
|
|
disableIframe: PropTypes.bool,
|
|
|
|
previewMounted: PropTypes.func.isRequired
|
2018-05-27 09:37:46 +01:00
|
|
|
};
|
|
|
|
|
2018-11-07 18:16:50 +00:00
|
|
|
class Preview extends Component {
|
2018-05-27 09:37:46 +01:00
|
|
|
constructor(...props) {
|
2018-05-29 15:34:50 +01:00
|
|
|
super(...props);
|
2018-05-27 09:37:46 +01:00
|
|
|
|
|
|
|
this.state = {
|
2018-09-30 11:37:19 +01:00
|
|
|
iframeStatus: props.disableIframe
|
2018-05-29 15:34:50 +01:00
|
|
|
};
|
2018-05-27 09:37:46 +01:00
|
|
|
}
|
|
|
|
|
2018-12-07 14:08:32 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.previewMounted();
|
|
|
|
}
|
|
|
|
|
2018-09-30 11:37:19 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (this.props.disableIframe !== prevProps.disableIframe) {
|
|
|
|
// eslint-disable-next-line react/no-did-update-set-state
|
2018-05-29 15:34:50 +01:00
|
|
|
this.setState({ iframeStatus: !this.state.iframeStatus });
|
2018-05-27 09:37:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const iframeToggle = this.state.iframeStatus ? 'disable' : 'enable';
|
|
|
|
return (
|
|
|
|
<div className={`challenge-preview ${iframeToggle}-iframe`}>
|
2018-09-30 11:37:19 +01:00
|
|
|
<iframe className={'challenge-preview-frame'} id={mainId} title='Challenge Preview'/>
|
2018-05-27 09:37:46 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-04-06 14:51:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Preview.displayName = 'Preview';
|
2018-05-27 09:37:46 +01:00
|
|
|
Preview.propTypes = propTypes;
|
2018-04-06 14:51:52 +01:00
|
|
|
|
2018-12-07 14:08:32 +02:00
|
|
|
export default connect(
|
|
|
|
null,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Preview);
|