Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
/**
2
* Copyright (c) 2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*/
9
10
var React = require('react');
11
var ReactPropTypes = React.PropTypes;
12
var TodoActions = require('../actions/TodoActions');
13
14
var Footer = React.createClass({
15
16
propTypes: {
17
allTodos: ReactPropTypes.object.isRequired
18
},
19
20
/**
21
* @return {object}
22
*/
23
render: function() {
24
var allTodos = this.props.allTodos;
25
var total = Object.keys(allTodos).length;
26
27
if (total === 0) {
28
return null;
29
}
30
31
var completed = 0;
32
for (var key in allTodos) {
33
if (allTodos[key].complete) {
34
completed++;
35
}
36
}
37
38
var itemsLeft = total - completed;
39
var itemsLeftPhrase = itemsLeft === 1 ? ' item ' : ' items ';
40
itemsLeftPhrase += 'left';
41
42
// Undefined and thus not rendered if no completed items are left.
43
var clearCompletedButton;
44
if (completed) {
45
clearCompletedButton =
46
<button
47
id="clear-completed"
48
onClick={this._onClearCompletedClick}>
49
Clear completed ({completed})
50
</button>;
51
}
52
53
return (
54
<footer id="footer">
55
<span id="todo-count">
56
<strong>
57
{itemsLeft}
58
</strong>
59
{itemsLeftPhrase}
60
</span>
61
{clearCompletedButton}
62
</footer>
63
);
64
},
65
66
/**
67
* Event handler to delete all completed TODOs
68
*/
69
_onClearCompletedClick: function() {
70
TodoActions.destroyCompleted();
71
}
72
73
});
74
75
module.exports = Footer;
76
77