From f6d7fcbb50ef57f1f7d7ca8cacd711ffd576e600 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 2 Jun 2020 17:38:14 +0200 Subject: showing pages for graph. getting urls right --- frontend/views/graph/graph.container.js | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 frontend/views/graph/graph.container.js (limited to 'frontend/views/graph/graph.container.js') diff --git a/frontend/views/graph/graph.container.js b/frontend/views/graph/graph.container.js new file mode 100644 index 0000000..40e2e6a --- /dev/null +++ b/frontend/views/graph/graph.container.js @@ -0,0 +1,66 @@ +import React, { Component } from 'react' +import { Route } from 'react-router-dom' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import './graph.css' + +import actions from '../../actions' +import { Loader } from '../../common' + +// import * as uploadActions from './upload.actions' + +// import GraphIndex from './containers/graph.index' + +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 null + if (this.props.graph.show.loading) { + return ( +
+ +
+ ) + } + console.log(this.props.graph.show) + return ( +
+
+ ) + } +} + + // +const mapStateToProps = state => ({ + graph: state.graph, +}) + +const mapDispatchToProps = dispatch => ({ + // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(GraphContainer) -- cgit v1.2.3-70-g09d2