import React, { Component } from 'react' import { Route } from 'react-router-dom' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import './page.css' import './cursors.css' import actions from '../../actions' import { Loader } from '../../common' import * as graphActions from '../graph/graph.actions' import * as pageActions from './page.actions' import PageEdit from '../graph/components/page.edit' import TileNew from './components/tile.new' import TileEdit from './components/tile.edit' import TileList from './components/tile.list' import PageHeader from './components/page.header' import PageEditor from './components/page.editor' class PageContainer extends Component { componentDidMount() { if (this.shouldShowPage()) this.load() } componentDidUpdate(prevProps) { if (this.shouldLoadPage(prevProps)) this.load() } shouldShowPage() { const { graph_name, page_name } = this.props.match.params // console.log(graph_name, page_name) return (graph_name && page_name && graph_name !== 'index') } shouldLoadPage(prevProps) { const { page, location } = this.props const { key } = location if (key === prevProps.location.key) return false if (!this.shouldShowPage()) return false return (page.show.name === prevProps.page.show.name) } load() { actions.site.setSiteTitle("loading " + this.props.match.params.page_name + "...") this.props.pageActions.showGraphAndPageIfUnloaded(this.props.match.params) .then(data => { actions.site.setSiteTitle(data.res.title) if (!data.res.tiles.length) { this.props.pageActions.showAddTileForm() } else { this.props.pageActions.hideAddTileForm() } }) } render() { if (!this.shouldShowPage()) return null if (!this.props.page.show.res || this.props.page.show.loading) { return (