re-enable scrolling, focus, and blur

This commit is contained in:
Connor Turland 2016-12-21 03:51:42 -05:00
parent 39afe4342b
commit 0558cabd8e
2 changed files with 10 additions and 10 deletions

View file

@ -120,16 +120,10 @@ const ChatView = {
ChatView.render() ChatView.render()
}, },
close: () => { close: () => {
// TODO how to do focus with react
// this.$messageInput.blur()
ChatView.mapChat.close() ChatView.mapChat.close()
}, },
open: () => { open: () => {
ChatView.mapChat.open() ChatView.mapChat.open()
// TODO how to do focus with react
// this.$messageInput.focus()
// TODO reimplement scrollMessages
// this.scrollMessages(0)
}, },
videoToggleClick: function() { videoToggleClick: function() {
ChatView.videosShowing = !ChatView.videosShowing ChatView.videosShowing = !ChatView.videosShowing
@ -153,10 +147,8 @@ const ChatView = {
if (!isInitial) self.mapChat.newMessage() if (!isInitial) self.mapChat.newMessage()
if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat') if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat')
self.messages.add(message) self.messages.add(message)
// TODO what is scrollMessages?
// scrollMessages scrolls to the bottom of the div when there's new messages“
// if (!isInitial) self.scrollMessages(200)
self.render() self.render()
if (!isInitial) self.mapChat.scroll()
}, },
sendChatMessage: message => { sendChatMessage: message => {
var self = ChatView var self = ChatView

View file

@ -31,17 +31,24 @@ class MapChat extends Component {
close = () => { close = () => {
this.setState({open: false}) this.setState({open: false})
this.props.onClose() this.props.onClose()
this.messageInput.blur()
} }
open = () => { open = () => {
this.scroll()
this.setState({open: true, unreadMessages: 0}) this.setState({open: true, unreadMessages: 0})
this.props.onOpen() this.props.onOpen()
this.messageInput.focus()
} }
newMessage = () => { newMessage = () => {
if (!this.state.open) this.setState({unreadMessages: this.state.unreadMessages + 1}) if (!this.state.open) this.setState({unreadMessages: this.state.unreadMessages + 1})
} }
scroll = () => {
this.messagesDiv.scrollTop = this.messagesDiv.scrollHeight
}
toggleDrawer = () => { toggleDrawer = () => {
if (this.state.open) this.close() if (this.state.open) this.close()
else if (!this.state.open) this.open() else if (!this.state.open) this.open()
@ -117,10 +124,11 @@ class MapChat extends Component {
<div className="tooltips">Chat</div> <div className="tooltips">Chat</div>
<Unread count={unreadMessages} /> <Unread count={unreadMessages} />
</div> </div>
<div className="chat-messages"> <div className="chat-messages" ref={div => this.messagesDiv = div}>
{messages.map(message => <Message key={message.id} {...message} />)} {messages.map(message => <Message key={message.id} {...message} />)}
</div> </div>
<textarea className="chat-input" <textarea className="chat-input"
ref={textarea => this.messageInput = textarea}
placeholder="Send a message..." placeholder="Send a message..."
value={this.state.messageText} value={this.state.messageText}
onChange={this.handleChange('messageText')} onChange={this.handleChange('messageText')}