-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
187 lines (141 loc) · 4.87 KB
/
index.html
File metadata and controls
187 lines (141 loc) · 4.87 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<head>
<title>Hello world</title>
<script src="http://fb.me/react-0.12.1.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.1.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
.NoteApp{
margin: 30px auto;
}
.SearchField{
width: 100%;
padding-right: 0px;
}
.textarea{
width: 100%;
height: 300px;
}
.NoteList{
margin-top: 10px;
padding-left: 0px;
list-style-type: none;
}
</style>
</head>
<body>
<script type="text/jsx">
var NOTES = [
{author: 'Amil', title: 'Amils Text', text: 'This is Amil here and this is my text'},
{author: 'Per', title: 'Pers Text', text: 'This is Per here and this is my text'},
{author: 'Ron', title: 'Rons Text', text: 'This is Ron here and this is my text'},
{author: 'John', title: 'John Text', text: 'This is John here and this is my text'},
{author: 'Nina', title: 'Nina Text', text: 'This is Nina here and this is my text'},
{author: 'Caroline', title: 'Caroline Text', text: 'This is Caroline here and this is my text'}
];
var IndivNote = React.createClass({
render: function(){
return (
<li>
<p> {this.props.note.title} </p>
<button onClick={this.props.remove} />
<button onClick={this.props.setActive} />
</li>
)
}
});
var NoteList = React.createClass({
render: function(){
var that = this;
var titles = [];
this.props.notes.forEach(function(note){
titles.push(<IndivNote note={note} setActive={that.props.setActive.bind(null,note)} remove={that.props.deleteNote.bind(null,note)} />)
});
return (
<ul className='NoteList'> {titles} </ul>
)
}
});
var SearchField = React.createClass({
render: function(){
return(
<input type="text" className="SearchField" />
)
}
});
var SearchableTable = React.createClass({
render: function(){
return (
<div className="SearchableTable col-md-4 col-lg-4 col-sm-4 col-xs-4">
<SearchField/>
<NoteList notes={this.props.notes} setActive={this.props.setActive} deleteNote={this.props.deleteNote} />
</div>
)
}
});
var TextEditor = React.createClass({
render: function(){
return(
<div className="TextEditor col-md-8 col-lg-8 col-sm-8 col-xs-12">
<textarea className="textarea" onChange={this.props.handleChange} value={this.props.notes[this.props.active_note_index].text}></textarea>
</div>
)
}
});
var NoteApp = React.createClass({
getInitialState: function() {
return {
notes : NOTES,
active_note_index: 0
}
},
setActive: function(note){
console.log('SetActive Triggered! Note:',note);
console.log('Index', this.state.notes.indexOf(note));
this.setState({
active_note_index: this.state.notes.indexOf(note)
})
},
handleChange: function(event){
var notes = this.state.notes;
notes[this.state.active_note_index].text = event.target.value;
this.setState({
notes: notes
})
},
deleteNote: function( note ){
// If the active note has a higher index than the one you're deleting.
if (this.state.notes.indexOf(note) < this.state.active_note_index ){
this.setState({
active_note_index: ( this.state.active_note_index - 1 )
})
}
// remove the selected note
this.state.notes.splice( this.state.notes.indexOf(note), 1 );
this.setState({notes:this.state.notes});
// if you're deleting the last item, then decrement the active note index with one (or else, the active_note_index will be out of ratio)
if ( this.state.active_note_index == this.state.notes.length ) {
console.log('OUT OF RATIO:');
console.log('active_note_index: ',this.state.active_note_index)
console.log('notes.length: ', this.state.notes.length )
this.setState({
active_note_index: (this.state.active_note_index -1 )
})
}
},
render: function(){
return (
<div className="NoteApp col-md-6 col-lg-6 col-sm-8 col-xs-10">
<SearchableTable notes={this.state.notes} setActive={this.setActive} deleteNote={this.deleteNote} />
<TextEditor handleChange={this.handleChange} notes={this.state.notes} active_note_index={this.state.active_note_index} />
</div>
)
}
});
React.render(<NoteApp/>, document.body);
</script>
</body>
</html>