blob: 525eb464366613fd8dc7367c65834050e3bdbd6e (
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
85
86
87
88
89
90
91
92
93
|
import React, { Component } from 'react'
import { TextArea, Button } from 'app/common'
import actions from 'app/actions'
export default class FootnoteForm extends Component {
state = {
editing: false,
footnote: {},
}
constructor(props) {
super(props)
this.edit = this.edit.bind(this)
this.handleChange = this.handleChange.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.handleCancel = this.handleCancel.bind(this)
}
componentDidMount() {
this.setState({ footnote: { ...this.props.footnote } })
}
edit() {
this.setState({ editing: true })
}
handleChange(e){
e.preventDefault()
this.setState({
footnote: {
...this.state.footnote,
text: e.target.value,
}
})
}
handleSubmit(e) {
e.preventDefault()
actions.annotation.update(this.state.footnote)
this.setState({ editing: false })
}
handleCancel(e) {
e.preventDefault()
this.setState({
editing: false,
footnote: { ...this.props.footnote }
})
}
render() {
return this.state.editing
? this.renderForm()
: this.renderEntry()
}
renderForm() {
const { index } = this.props
const { footnote } = this.state
return (
<form className='footnote-form' onSubmit={this.handleSubmit}>
<TextArea
title={`Edit footnote ${index}`}
name="text"
placeholder="Enter footnote"
data={footnote}
onChange={this.handleChange}
/>
<div className='buttons'>
<span></span>
<div>
<button onClick={this.handleSubmit}>Save footnote</button>
<button onClick={this.handleCancel}>Cancel</button>
</div>
</div>
</form>
)
}
renderEntry() {
const { index } = this.props
const { footnote } = this.state
return (
<div className='footnote-entry' onClick={this.edit}>
<div className='footnote-index'>
{index}{'. '}
</div>
<div className='footnote-text' dangerouslySetInnerHTML={{ __html: footnote.text }} />
</div>
)
}
}
|