/
Rooms.js
59 lines (51 loc) · 1.49 KB
/
Rooms.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
import React from 'react';
import { socketConnect } from 'socket.io-react';
import Room from './Room';
import RoomsStore from '../stores/RoomsStore';
import * as RoomsActions from '../actions/RoomsActions';
const roomsStyle = {
width: '100%',
margin: '20px auto',
padding: '20px',
listStyle: 'none'
};
@socketConnect
export default class Rooms extends React.Component {
constructor() {
super();
this.state = {
rooms: RoomsStore.getAll()
};
}
componentWillMount() {
RoomsStore.on('addNewRoom', (data) => {
this.setState({
rooms: RoomsStore.getAll()
});
// 1 room and 2 users have been comfirmed. Now join them into the room.
this.props.socket.emit('join_private_room', data);
});
RoomsStore.on('updateRooms', () => {
this.setState({
rooms: RoomsStore.getAll()
});
});
this.props.socket.on('invite_match_user', (data) => {
// Let's go and see if the username belongs to the room!
RoomsActions.matchUser(data);
});
}
render() {
const {rooms} = this.state;
const roomComponents = rooms.map((data) => {
return <Room key={data.room} info={data} />;
});
return(
<div>
<ul class="rooms" style={roomsStyle}>
{roomComponents}
</ul>
</div>
);
}
}