summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/editor/editor.gate.js
blob: b835a690c6421afa54538747ae854ca2138eb1f6 (plain)
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
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { Loader } from 'app/common'

import actions from 'app/actions'

class EditorGate extends Component {
  constructor(props) {
    super(props)
    this.load()
  }

  componentDidMount() {
    this.load()
  }

  componentDidUpdate(prevProps) {
    if (
      this.props.episode_id !== prevProps.episode_id ||
      this.props.episode.lookup !== prevProps.episode.lookup
    ) {
      this.load()
    }
  }

  load() {
    if (!this.props.episode.lookup) return
    if (!this.props.episode_id) return
    const episode = this.props.episode.lookup[this.props.episode_id]
    actions.site.loadEpisode(episode)
  }

  render() {
    if (parseInt(this.props.episode_id) === parseInt(this.props.currentEpisodeId)) {
      return this.props.children
    }
    return (
      <div className="dashboard"><Loader /></div>
    )
  }
}

const mapStateToProps = state => ({
  episode: state.episode.index,
  currentEpisodeId: state.align.currentEpisodeId,
})

export default connect(mapStateToProps)(EditorGate)