-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeed.jsx
49 lines (44 loc) · 1.08 KB
/
Feed.jsx
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
import React from 'react';
import { Link } from 'react-router';
import firebase from 'firebase';
import FeedRow from './FeedRow.jsx';
class Feed extends React.Component {
constructor(props) {
super(props);
this.state = {
events: [],
};
}
componentWillMount() {
this.firebaseRef = firebase.database().ref('feed')
.orderByChild('date')
.limitToLast(20);
this.firebaseRef.on('value', function(dataSnapshot) {
var events = [];
dataSnapshot.forEach(function(childSnapshot) {
var feedEvent = childSnapshot.val();
feedEvent['.key'] = childSnapshot.key;
events.push(feedEvent);
}.bind(this));
events.reverse();
this.setState({
events: events
});
}.bind(this));
}
render() {
var createEventRow = function(feedEvent, index) {
return (
<FeedRow feedEvent={feedEvent}/>
);
};
return (
<table className="table table-hover">
<tbody>
{this.state.events.map(createEventRow)}
</tbody>
</table>
);
}
}
export default Feed;