@@ -49,13 +49,17 @@ class ListOfTasks extends React.Component {
49
49
componentDidMount ( ) {
50
50
this . setState ( { data : list } )
51
51
window . ee . on ( 'List.add' , ( item ) => {
52
- let added = item . concat ( this . state . data )
52
+ let added = item . concat ( this . state . data )
53
53
this . setState ( { data : added } )
54
54
} )
55
55
}
56
56
57
+ componentWillUnmount ( ) {
58
+ window . ee . off ( 'List.add' )
59
+ }
60
+
57
61
render ( ) {
58
- let newTemplate
62
+ let newTemplate
59
63
if ( this . state . data . length > 0 ) {
60
64
newTemplate = this . state . data . map ( ( item , index ) => {
61
65
return (
@@ -90,6 +94,10 @@ class Add extends React.Component {
90
94
constructor ( props ) {
91
95
super ( props )
92
96
this . addButton = this . addButton . bind ( this )
97
+ this . rulesAccepter = this . rulesAccepter . bind ( this )
98
+ this . state = {
99
+ agree : false
100
+ }
93
101
}
94
102
95
103
componentDidMount ( ) {
@@ -105,6 +113,10 @@ class Add extends React.Component {
105
113
window . ee . emit ( 'List.add' , item )
106
114
}
107
115
116
+ rulesAccepter ( e ) {
117
+ this . setState ( { agree : e . target . checked } )
118
+ }
119
+
108
120
render ( ) {
109
121
return (
110
122
< div >
@@ -113,9 +125,9 @@ class Add extends React.Component {
113
125
placeholder = 'author' ref = "author" />
114
126
< input type = "text" ref = "book" placeholder = "book" defaultValue = "" />
115
127
< label htmlFor = "" >
116
- < input type = "checkbox" defaultChecked = { false } ref = "checkrule" />
128
+ < input onChange = { this . rulesAccepter } type = "checkbox" defaultChecked = { false } ref = "checkrule" />
117
129
</ label >
118
- < button onClick = { this . addButton } > value</ button >
130
+ < button disabled = { ! this . state . agree } onClick = { this . addButton } > value</ button >
119
131
</ div >
120
132
)
121
133
}
0 commit comments