import React, { Component } from 'react' import { connect } from 'react-redux' import './graph.css' import actions from 'app/actions' import { Loader } from 'app/common' // import * as uploadActions from './upload.actions' import PageNew from './components/page.new' import PageEdit from './components/page.edit' import GraphHeader from './components/graph.header' import GraphEditor from './components/graph.editor' import AudioList from './components/audio.list' import CursorList from './components/cursor.list' class GraphContainer extends Component { componentDidMount() { if (this.shouldShowGraph()) this.load() } componentDidUpdate(prevProps) { if (this.shouldLoadGraph(prevProps)) this.load() } shouldShowGraph() { const { graph_name, page_name } = this.props.match.params return (graph_name && !page_name && graph_name !== 'index') } shouldLoadGraph(prevProps) { const { graph, location } = this.props const { key } = location if (key === prevProps.location.key) return false if (!this.shouldShowGraph()) return false return (graph.show.name === prevProps.graph.show.name) } load() { actions.site.setSiteTitle("loading " + this.props.match.params.graph_name + "...") actions.graph.show('name/' + this.props.match.params.graph_name) .then(data => { actions.site.setSiteTitle(data.res.title) }) } render() { if (!this.shouldShowGraph()) return
if (!this.props.graph.show.res || this.props.graph.show.loading) { return (
) } return (
{this.props.graph.editor.addingPage && } {this.props.graph.editor.editingPage && } {this.props.graph.editor.showingAudio && } {this.props.graph.editor.showingCursors && }
) } } // const mapStateToProps = state => ({ graph: state.graph, }) export default connect(mapStateToProps)(GraphContainer)