import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
// import { is, fromJS } from 'immutable'
|
import { Form, Icon, Popover, Input } from 'antd'
|
|
import zhCN from '@/locales/zh-CN/mob.js'
|
import enUS from '@/locales/en-US/mob.js'
|
import './index.scss'
|
|
class ContentUpdate extends Component {
|
static propTpyes = {
|
element: PropTypes.object,
|
updateContent: PropTypes.func
|
}
|
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
visible: false
|
}
|
|
UNSAFE_componentWillMount () {
|
|
}
|
|
// shouldComponentUpdate (nextProps, nextState) {
|
// return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
// }
|
|
onVisibleChange = (visible) => {
|
const { element } = this.props
|
let val = this.props.form.getFieldValue('content')
|
|
this.setState({
|
visible: visible
|
})
|
|
if (val && element.content !== val) {
|
this.props.updateContent({...element, content: val})
|
} else {
|
this.props.form.setFieldsValue({content: element.content})
|
}
|
}
|
|
handleSubmit = () => {
|
const { element } = this.props
|
let val = this.props.form.getFieldValue('content')
|
|
this.setState({
|
visible: false
|
})
|
|
if (val && element.content !== val) {
|
this.props.updateContent({...element, content: val})
|
} else {
|
this.props.form.setFieldsValue({content: element.content})
|
}
|
}
|
|
render () {
|
const { element } = this.props
|
const { getFieldDecorator } = this.props.form
|
const { visible } = this.state
|
|
return (
|
<div className="mob-content-update">
|
<Popover content={
|
<div>
|
{getFieldDecorator('content', {
|
initialValue: element.content
|
})(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
|
</div>
|
} overlayClassName="mob-content-update-popover" placement="bottomRight" title="" visible={visible} trigger="click" onVisibleChange={this.onVisibleChange}>
|
<Icon type="edit" />
|
</Popover>
|
</div>
|
)
|
}
|
}
|
|
export default Form.create()(ContentUpdate)
|