blob: 2ea09d14060c6569fddd68f9660cc93ff3556f8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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)
|