Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
/**
2
* Copyright (c) 2014-2015, 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
var TodoItem = require('./TodoItem.react');
14
15
var MainSection = React.createClass({
16
17
propTypes: {
18
allTodos: ReactPropTypes.object.isRequired,
19
areAllComplete: ReactPropTypes.bool.isRequired
20
},
21
22
/**
23
* @return {object}
24
*/
25
render: function() {
26
// This section should be hidden by default
27
// and shown when there are todos.
28
if (Object.keys(this.props.allTodos).length < 1) {
29
return null;
30
}
31
32
var allTodos = this.props.allTodos;
33
var todos = [];
34
35
for (var key in allTodos) {
36
todos.push(<TodoItem key={key} todo={allTodos[key]} />);
37
}
38
39
return (
40
<section id="main">
41
<input
42
id="toggle-all"
43
type="checkbox"
44
onChange={this._onToggleCompleteAll}
45
checked={this.props.areAllComplete ? 'checked' : ''}
46
/>
47
<label htmlFor="toggle-all">Mark all as complete</label>
48
<ul id="todo-list">{todos}</ul>
49
</section>
50
);
51
},
52
53
/**
54
* Event handler to mark all TODOs as complete
55
*/
56
_onToggleCompleteAll: function() {
57
TodoActions.toggleCompleteAll();
58
}
59
60
});
61
62
module.exports = MainSection;
63
64