Skip to content
Closed
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
4 changes: 3 additions & 1 deletion app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class App extends Component {
});
}

onSendMessage(message){
onSendMessage(message, onMessageSuccess, onMessageError){
this.setState({
isLoadingMessages: true
});
Expand All @@ -86,7 +86,9 @@ export default class App extends Component {
createMessage(currentRoomKey, message, username)
.then((response) => {
this.loadChatMessages(currentRoomKey);
onMessageSuccess();
}, (respErr) => {
onMessageError();
console.log("Error creating message: " + respErr);
});
}
Expand Down
28 changes: 24 additions & 4 deletions app/components/chat/MessageForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,42 @@ class MessageForm extends Component {
super(props);

this.onSendMessage = this.onSendMessage.bind(this);
this.onMessageSuccess = this.onMessageSuccess.bind(this);
this.onMessageError = this.onMessageError.bind(this);
}

componentDidMount(){
ReactDOM.findDOMNode(this.refs.messageBox).focus();
}

disableMessageBox(){
let box = $(ReactDOM.findDOMNode(this.refs.messageBox));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimmcgaw What does the $(...) do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes the input element on the message form a jquery-wrapped set. It just gives us the syntactic sugar for .prop and .removeAttr.

box.prop('disabled', 'disabled');
}

enableMessageBox(){
let box = $(ReactDOM.findDOMNode(this.refs.messageBox));
box.removeAttr('disabled');
}

onMessageSuccess(){
this.enableMessageBox()
let box = $(ReactDOM.findDOMNode(this.refs.messageBox));
box.val('')
}

onMessageError(){
this.enableMessageBox();
}

onSendMessage(e){
e.preventDefault();

// this approach is only marginally less shitty than
// passing the value up the component tree on each keystroke.
let messageBox = ReactDOM.findDOMNode(this.refs.messageBox);
let message = messageBox.value;
if (message && message.length > 0){
this.props.onSendMessage(message);
messageBox.value = '';
this.disableMessageBox();
this.props.onSendMessage(message, this.onMessageSuccess, this.onMessageError);
}
}

Expand Down