summaryrefslogtreecommitdiff
path: root/frontend/app/views/page/components/tile.edit.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/views/page/components/tile.edit.js')
-rw-r--r--frontend/app/views/page/components/tile.edit.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/frontend/app/views/page/components/tile.edit.js b/frontend/app/views/page/components/tile.edit.js
new file mode 100644
index 0000000..2ea09d1
--- /dev/null
+++ b/frontend/app/views/page/components/tile.edit.js
@@ -0,0 +1,84 @@
+import React, { Component } from 'react'
+// import { Link } from 'react-router-dom'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+// import { history } from 'app/store'
+import actions from 'app/actions'
+import * as pageActions from '../../page/page.actions'
+import * as tileActions from '../../tile/tile.actions'
+
+import { Loader } from 'app/common'
+
+import TileForm from '../components/tile.form'
+
+class TileEdit extends Component {
+ state = {
+ tile: null
+ }
+
+ componentDidMount() {
+ this.load()
+ }
+
+ componentDidUpdate(prevProps) {
+ if (prevProps.page.editor.currentEditTileId !== this.props.page.editor.currentEditTileId) {
+ this.load()
+ }
+ }
+
+ load() {
+ const { currentEditTileId } = this.props.page.editor
+ const tile = this.props.page.show.res.tiles.filter(tile => tile.id === currentEditTileId)[0]
+ console.log('edit', currentEditTileId)
+ this.setState({ tile })
+ }
+
+ handleSubmit(data) {
+ actions.tile.update(data)
+ .then(response => {
+ // console.log(response)
+ if (response.status === 'ok') {
+ this.props.pageActions.updatePageTile(response.res)
+ }
+ })
+ }
+
+ handleClose() {
+ this.props.pageActions.hideEditTileForm()
+ this.props.tileActions.clearTemporaryTile()
+ }
+
+ render() {
+ const { tile } = this.state
+ if (!tile) {
+ return (
+ <div className='form'>
+ <Loader />
+ </div>
+ )
+ }
+ return (
+ <TileForm
+ initialData={tile}
+ graph={this.props.graph.show.res}
+ page={this.props.page.show.res}
+ onSubmit={this.handleSubmit.bind(this)}
+ onClose={this.handleClose.bind(this)}
+ />
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ graph: state.graph,
+ page: state.page,
+ tile: state.tile,
+})
+
+const mapDispatchToProps = dispatch => ({
+ pageActions: bindActionCreators({ ...pageActions }, dispatch),
+ tileActions: bindActionCreators({ ...tileActions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(TileEdit)