Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80698 views
1
/**
2
* This file is provided by Facebook for testing and evaluation purposes
3
* only. Facebook reserves all rights not expressly granted.
4
*
5
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
8
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
9
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
10
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
*/
12
13
var React = require('react');
14
var MessageStore = require('../stores/MessageStore');
15
var ThreadListItem = require('../components/ThreadListItem.react');
16
var ThreadStore = require('../stores/ThreadStore');
17
var UnreadThreadStore = require('../stores/UnreadThreadStore');
18
19
function getStateFromStores() {
20
return {
21
threads: ThreadStore.getAllChrono(),
22
currentThreadID: ThreadStore.getCurrentID(),
23
unreadCount: UnreadThreadStore.getCount()
24
};
25
}
26
27
var ThreadSection = React.createClass({
28
29
getInitialState: function() {
30
return getStateFromStores();
31
},
32
33
componentDidMount: function() {
34
ThreadStore.addChangeListener(this._onChange);
35
UnreadThreadStore.addChangeListener(this._onChange);
36
},
37
38
componentWillUnmount: function() {
39
ThreadStore.removeChangeListener(this._onChange);
40
UnreadThreadStore.removeChangeListener(this._onChange);
41
},
42
43
render: function() {
44
var threadListItems = this.state.threads.map(function(thread) {
45
return (
46
<ThreadListItem
47
key={thread.id}
48
thread={thread}
49
currentThreadID={this.state.currentThreadID}
50
/>
51
);
52
}, this);
53
var unread =
54
this.state.unreadCount === 0 ?
55
null :
56
<span>Unread threads: {this.state.unreadCount}</span>;
57
return (
58
<div className="thread-section">
59
<div className="thread-count">
60
{unread}
61
</div>
62
<ul className="thread-list">
63
{threadListItems}
64
</ul>
65
</div>
66
);
67
},
68
69
/**
70
* Event handler for 'change' events coming from the stores
71
*/
72
_onChange: function() {
73
this.setState(getStateFromStores());
74
}
75
76
});
77
78
module.exports = ThreadSection;
79
80