-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessages.js
68 lines (49 loc) · 1.19 KB
/
Messages.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { Component } from 'react';
import firebase from '../lib/fire'
// import LazyLoad from 'react-lazy-load';
import { Link } from 'react-router-dom'
class Messages extends Component {
constructor(props){
super(props);
this.state={
groupId:"",
messagesList:[]
}
}
getAllMessagesFromCloud(groupId) {
var callback = function(snapshot) {
var list=[]
var data = snapshot.val();
for(var key in data) {
var op = data[key];
if(op.message)
list.push(op);
}
this.setState({messagesList:list});
console.log(list)
}.bind(this)
firebase.database().ref('messageInfo/'+groupId).on('value',callback);
}
componentDidMount() {
var {groupId}=this.props;
this.setState({groupId:groupId});
this.getAllMessagesFromCloud(groupId);
}
render() {
return (
<ul className="collection with-header">
{
this.state.messagesList.map(function(op,i){
console.log(op)
return(
<div>
<li key={i} className ="collection-item" >{op.message +"-"+ op.sendBy}</li>
</div>
);
})
}
</ul>
);
}
}
export default Messages