Skip to content

Commit 6ff8591

Browse files
committed
Firebase - Section 15
1 parent 4650605 commit 6ff8591

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

todos/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
.input-group {
1212
margin-bottom: 15px;
1313
}
14+
.clear-complete {
15+
margin-bottom: 15px;
16+
}
1417
</style>
1518
</head>
1619
<body>

todos/src/app.jsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var App = React.createClass({
1414
}
1515
},
1616
componentWillMount: function() {
17-
fb = new Firebase(rootUrl + 'items/');
18-
this.bindAsObject(fb, 'items');
19-
fb.on('value', this.handleDataLoaded);
17+
this.fb = new Firebase(rootUrl + 'items/');
18+
this.bindAsObject(this.fb, 'items');
19+
this.fb.on('value', this.handleDataLoaded);
2020
},
2121
render: function() {
2222
return <div className="row panel panel-default">
@@ -28,10 +28,33 @@ var App = React.createClass({
2828
<hr />
2929
<div className={"content " + (this.state.loaded ? 'loaded' : '')}>
3030
<List items={this.state.items} />
31+
{this.deleteButton()}
3132
</div>
3233
</div>
3334
</div>
3435
},
36+
deleteButton: function() {
37+
if(!this.state.loaded) {
38+
return
39+
} else {
40+
return <div className="text-center clear-complete">
41+
<hr />
42+
<button
43+
type="button"
44+
onClick={this.onDeleteDoneClick}
45+
className="btn btn-default">
46+
Clear Complete
47+
</button>
48+
</div>
49+
}
50+
},
51+
onDeleteDoneClick: function() {
52+
for(var key in this.state.items) {
53+
if(this.state.items[key].done === true) {
54+
this.fb.child(key).remove();
55+
}
56+
}
57+
},
3558
handleDataLoaded: function(){
3659
this.setState({loaded: true});
3760
}

todos/src/list.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = React.createClass({
88
</div>
99
},
1010
renderList: function() {
11-
if(this.props.items && Object.keys(this.props.items).length === 0) {
11+
if(!this.props.items) {
1212
return <h4>
1313
Add a todo to get started.
1414
</h4>

0 commit comments

Comments
 (0)