Skip to content

Commit b781bd2

Browse files
committed
adding books with agrees
1 parent 769443a commit b781bd2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

public/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@
3636
To begin the development, run `npm start` or `yarn start`.
3737
To create a production bundle, use `npm run build` or `yarn build`.
3838
-->
39-
<script src="https://raw.githubusercontent.com/Olical/EventEmitter/master/EventEmitter.min.js"></script>
4039
</body>
4140
</html>

src/App.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ class ListOfTasks extends React.Component {
4949
componentDidMount() {
5050
this.setState({data: list})
5151
window.ee.on('List.add', (item) => {
52-
let added = item.concat(this.state.data)
52+
let added = item.concat(this.state.data)
5353
this.setState({data: added})
5454
})
5555
}
5656

57+
componentWillUnmount() {
58+
window.ee.off('List.add')
59+
}
60+
5761
render() {
58-
let newTemplate
62+
let newTemplate
5963
if (this.state.data.length > 0) {
6064
newTemplate = this.state.data.map((item, index) => {
6165
return (
@@ -90,6 +94,10 @@ class Add extends React.Component {
9094
constructor(props) {
9195
super(props)
9296
this.addButton = this.addButton.bind(this)
97+
this.rulesAccepter = this.rulesAccepter.bind(this)
98+
this.state = {
99+
agree: false
100+
}
93101
}
94102

95103
componentDidMount() {
@@ -105,6 +113,10 @@ class Add extends React.Component {
105113
window.ee.emit('List.add', item)
106114
}
107115

116+
rulesAccepter(e) {
117+
this.setState({agree: e.target.checked})
118+
}
119+
108120
render() {
109121
return (
110122
<div>
@@ -113,9 +125,9 @@ class Add extends React.Component {
113125
placeholder='author' ref="author"/>
114126
<input type="text" ref="book" placeholder="book" defaultValue=""/>
115127
<label htmlFor="">
116-
<input type="checkbox" defaultChecked={false} ref="checkrule"/>
128+
<input onChange={this.rulesAccepter} type="checkbox" defaultChecked={false} ref="checkrule"/>
117129
</label>
118-
<button onClick={this.addButton}>value</button>
130+
<button disabled={!this.state.agree} onClick={this.addButton}>value</button>
119131
</div>
120132
)
121133
}

0 commit comments

Comments
 (0)