diff options
Diffstat (limited to 'frontend/views/page/page.container.js')
| -rw-r--r-- | frontend/views/page/page.container.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/frontend/views/page/page.container.js b/frontend/views/page/page.container.js new file mode 100644 index 0000000..2de56bb --- /dev/null +++ b/frontend/views/page/page.container.js @@ -0,0 +1,81 @@ +import React, { Component } from 'react' +import { Route } from 'react-router-dom' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import './page.css' + +import actions from '../../actions' +import { Loader } from '../../common' + +// import * as uploadActions from './upload.actions' + +import TileNew from './components/tile.new' +import TileEdit from './components/tile.edit' + +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 + "...") + actions.page.show('name/' + this.props.match.params.graph_name + '/' + this.props.match.params.page_name) + .then(data => { + actions.site.setSiteTitle(data.res.title) + }) + } + render() { + if (!this.shouldShowPage()) return null + if (!this.props.page.show.res || this.props.page.show.loading) { + return ( + <div> + <PageHeader /> + <div className='body'> + <div className='page loading'> + <Loader /> + </div> + </div> + </div> + ) + } + return ( + <div> + <PageHeader /> + <div className='body'> + <PageEditor /> + {this.props.page.editor.addingTile && <TileNew />} + {this.props.page.editor.editingTile && <TileEdit />} + </div> + </div> + ) + } +} + +const mapStateToProps = state => ({ + graph: state.graph, + page: state.page, +}) + +const mapDispatchToProps = dispatch => ({ + // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(PageContainer) |
