Skip to content

Instantly share code, notes, and snippets.

@sairion
Created November 16, 2015 07:19
Show Gist options
  • Save sairion/e11d235600668796ce39 to your computer and use it in GitHub Desktop.
Save sairion/e11d235600668796ce39 to your computer and use it in GitHub Desktop.
class Chat extends React.Component {
constructor(props) {
super();
this.state = {
users: [],
messages:[],
text: '',
status: 'userEnter'
};
this.statusProps = {
'userEnter': {
modalDisplay: true,
modalInput: true,
modalMessage: "What is user name?"
},
'error': {
modalDisplay: true,
modalInput: false,
modalMessage: "There was an error, please retry!"
}
}
this.handleMessageSubmit.bind(this);
this.handleModalSubmit.bind(this);
}
componentDidMount() {
this.connection = new ChatConnection(this);
}
handleMessageSubmit(message) {
var {messages} = this.state;
messages.push(message);
this.setState({messages});
this.connection.socket.emit('send:message', message);
}
handleModalSubmit(e) {
if (this.state.status === 'userEnter') {
var input = e.target.value;
}
}
render() {
var statusProp = this.statusProps[this.state.status];
return (
<div>
<StatusBar user={this.state.user}
users={this.state.users} />
<ChatRoom onMessageSubmit={this.handleMessageSubmit}
messages={this.state.messages}
user={this.state.user} />
<Modal onSubmit={this.handleModalSubmit}
message={statusProp.message}
modalDisplay={statusProp.modalDisplay} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment