-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
148 lines (126 loc) · 4.88 KB
/
index.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>New React Proj</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script src="js/react.development.js"></script>
<script src="js/react-dom.development.js"></script>
<script src="js/babel.min.js"></script>
</head>
<body>
<header>
<div class="jumbotron">
<div class="container">
<h1 class="display-4">Notes</h1>
<p class="lead">Simple notes app using React.</p>
</div>
</div>
</header>
<div id="root" class="container"></div>
<script type="text/babel">
class Note extends React.Component{
state = {editing : 0};
editfunc = () => {
this.setState({ editing : true });
}
delfunc = () => {
this.props.deleteNote(this.props.index);
}
savefunc = () => {
var newtext = this.refs.edited.value;
if(newtext.length<1){
alert("Please enter text to save!");
}
else{
this.props.editNote(newtext, this.props.index);
this.setState({ editing : false });
}
}
render(){
if(this.state.editing==true)
return (
<div className="card m-3">
<div className="card-body">
<textarea className="form-control" rows="2" ref='edited' defaultValue={this.props.children}></textarea>
<button className="btn btn-outline-success my-3" onClick={this.savefunc}>Save</button>
</div>
</div>)
else return (
<div className="card my-3">
<div className="card-body">
<h5 className="card-title">{this.props.children}</h5>
<div className="btn-group" role="group">
<button className="btn btn-outline-info" onClick={this.editfunc}>Edit</button>
<button className="btn btn-outline-danger" onClick={this.delfunc}>Delete</button>
</div>
</div>
</div>)
}
}
class Board extends React.Component{
state = { notes : [
'Hello world! This is Shashwat Uttam',
]};
constructor(props, context){
super(props, context);
this.deletenote = this.deletenote.bind(this);
this.editnote = this.editnote.bind(this);
}
addnote = () => {
var newtext = this.refs.inputnote.value;
if(newtext.length<1){
alert("Please enter text to save!");
}
else{
var arr = this.state.notes;
arr.push(newtext);
this.setState({ notes : arr });
document.getElementById("inputnote").value = "";
}
};
editnote = (newtext,i) => {
var arr = this.state.notes;
arr[i] = newtext;
this.setState({notes : arr});
};
deletenote = (i) => {
var arr = this.state.notes;
arr.splice(i,1);
this.setState({notes : arr});
};
eachnote(text,i){
return(
<Note key={i} index={i} deleteNote={this.deletenote} editNote={this.editnote}>
{text}
</Note>
);
}
render(){
return (
<div>
<div className="row">
<div className="col-sm-10">
<input type="text" ref="inputnote" id="inputnote" className="form-control form-control-lg my-3" placeholder="Add a note!"/>
</div>
<div className="col-sm-2">
<button type="submit" className="btn btn-lg btn-primary my-3" onClick={this.addnote}>Add</button>
</div>
</div>
<br/>
{this.state.notes.map(this.eachnote, this)}
</div>
)
}
}
ReactDOM.render(<div>
<Board/>
</div>,document.getElementById('root'));
</script>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
</body>
</html>