-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
112 lines (95 loc) · 2.35 KB
/
app.js
File metadata and controls
112 lines (95 loc) · 2.35 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// DEPRECATED! Use index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
class Notification extends React.Component {
constructor(props){
super(props)
this.state = {
isOpen: this.props.isOpen
}
this.close = this.close.bind(this);
}
componentDidMount() {
const self = this;
setTimeout(function(){
self.close();
}, 2000);
}
close() {
console.log("before: ",this.state.isOpen);
this.props.closePopup();
}
render() {
const visible = this.state.isOpen;
if (visible) {
return (
<div className="warning">
<p>This is an error!</p>
<span onClick={this.close}>X</span>
</div>
)
}
return false;
}
}
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [
{ text: "Learn JavaScript", done: false },
{ text: "Learn React", done: false },
{ text: "Play around in JSFiddle", done: true },
{ text: "Build something awesome", done: true }
],
showPopup: false
}
}
render() {
return (
<div>
<h2>Todos:</h2>
<ol>
{this.state.items.map((item, a) => (
<li key={a}>
<label>
<input type="checkbox" disabled readOnly checked={item.done} />
<span className={item.done ? "done" : ""}>{item.text}</span>
</label>
</li>
))}
</ol>
</div>
)
}
}
class Container extends React.Component {
constructor(props) {
super(props)
this.state = {
showPopup: false
}
}
openNotification = () => {
this.setState({ showPopup: !this.state.showPopup }, () => {
console.log("state: ", this.state.showPopup);
});
}
closeNotification = () => {
this.setState({
showPopup: !this.state.showPopup
}, () => {
console.log("After close: ", this.state.showPopup);
})
}
render() {
return (
<div>
<TodoApp className="todolist"></TodoApp>
{ this.state.showPopup ? <Notification isOpen={this.state.showPopup} closePopup={this.closeNotification}></Notification> : null }
<button className="btn-del" onClick={this.openNotification}>Remove crop</button>
</div>
)
}
}
ReactDOM.render(<Container />, document.querySelector("#main"))