Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import {MessageList, MessageRow, MessageInput} from './MesaageBox';
import Login from './Login';
import feed from './feed-socketio';
import UserList from './UserList';

import RoomList from './RoomList';
export default class HomePage extends Component {
constructor(props) {
super(props);
var msgs = [];
this.state = {
msgs: msgs,
userName: '',
userList: []
userList: [],
RoomList: ["123","456"],
};
this._sendMsg = this._sendMsg.bind(this);
this._handleLogin = this._handleLogin.bind(this);
this._addRoom = this._addRoom.bind(this);
}
componentDidMount() {
let _self = this;
Expand All @@ -23,6 +25,10 @@ export default class HomePage extends Component {
userName: msg
});
});
feed.watchRoomList(RoomList => {
console.log(RoomList);
_self.setState({RoomList: RoomList});
});
feed.watchChat(msg => {
let msgs = _self.state.msgs;
msgs.push(msg);
Expand All @@ -32,6 +38,15 @@ export default class HomePage extends Component {
_self.setState({userList: userList});
});
}
_addRoom(roomName) {
feed.addRoom(roomName);
}
_RoomList(){
feed.watchRoomList(RoomList => {
console.log(RoomList);
this.setState({RoomList: RoomList});
});
}
_sendMsg(msg) {
feed.sendMsg(msg);
}
Expand All @@ -43,6 +58,7 @@ export default class HomePage extends Component {
var rows = userName && userName.length > 0 ? (
<div>
<MessageList msgs={this.state.msgs} />
<RoomList RoomList={this.state.RoomList} _addRoom={this._addRoom}/>
<UserList userList={this.state.userList} />
<MessageInput sendMessage={this._sendMsg}/>
</div>
Expand Down
47 changes: 47 additions & 0 deletions src/RoomList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {Component} from 'react';

var divStyle = {
color: 'white'
};

export default class RoomList extends Component {
constructor(props) {
super(props);
this.state = {
input: ''
};
this._handleChange = this._handleChange.bind(this);
this._onClickAddRoom = this._onClickAddRoom.bind(this);
}
_onClickAddRoom () {
var addRoom = this.state.input.trim();
this.props._addRoom(addRoom);
}
_handleChange(e) {
this.setState({
input: e.currentTarget.value
});
}
render() {
return (
<div id="RoomListBox">
<input
type="text"
value={this.state.input}
onChange={this._handleChange}/>
<button onClick={this._onClickAddRoom}>add Room</button>
<ul>
{
this.props.RoomList.map((result,index) => {
return <li key={index}>
<a href="#" title={result}>
{result}
</a>
</li>;
})
}
</ul>
</div>
);
}
}