import React, { Component } from 'react' import { connect } from 'react-redux' import { Loader } from 'app/common' import actions from 'app/actions' class EditorGate extends Component { state = { ready: false, } constructor(props) { super(props) } componentDidMount() { this.load() } componentDidUpdate(prevProps) { if ( this.props.episode_id !== prevProps.episode_id || this.props.episode.lookup !== prevProps.episode.lookup || this.props.project.lookup !== prevProps.project.lookup ) { this.load() } } load() { if (!this.props.project.lookup) return if (!this.props.episode.lookup) return if (!this.props.episode_id) return if (parseInt(this.props.episode_id) === parseInt(this.props.current_episode_id)) return this.setState({ ready: false }) const episode = this.props.episode.lookup[this.props.episode_id] const project = this.props.project.lookup[episode.project_id] actions.site.loadEpisode(project, episode) .then(() => { this.setState({ ready: true }) }) } render() { if (this.state.ready && parseInt(this.props.episode_id) === parseInt(this.props.current_episode_id)) { return this.props.children } return (