move Handlers code into react - woot
This commit is contained in:
parent
f51a155879
commit
b1bfa757cb
3 changed files with 96 additions and 92 deletions
|
@ -187,7 +187,6 @@ let Realtime = {
|
||||||
self.room.videoAdded(self.handleVideoAdded)
|
self.room.videoAdded(self.handleVideoAdded)
|
||||||
|
|
||||||
if (Active.Map) {
|
if (Active.Map) {
|
||||||
self.room.chat.addWrapper()
|
|
||||||
self.room.chat.render()
|
self.room.chat.render()
|
||||||
}
|
}
|
||||||
} // if Active.Mapper
|
} // if Active.Mapper
|
||||||
|
|
|
@ -39,31 +39,6 @@ const ChatView = {
|
||||||
sessioninvite: [4000, 5393, true]
|
sessioninvite: [4000, 5393, true]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO move these event handlers into react
|
|
||||||
// this.$button.on('click', function() {
|
|
||||||
// Handlers.buttonClick.call(self)
|
|
||||||
// })
|
|
||||||
// this.$videoToggle.on('click', function() {
|
|
||||||
// Handlers.videoToggleClick.call(self)
|
|
||||||
// })
|
|
||||||
// this.$cursorToggle.on('click', function() {
|
|
||||||
// Handlers.cursorToggleClick.call(self)
|
|
||||||
// })
|
|
||||||
// this.$soundToggle.on('click', function() {
|
|
||||||
// Handlers.soundToggleClick.call(self)
|
|
||||||
// })
|
|
||||||
// this.$messageInput.on('keyup', function(event) {
|
|
||||||
// Handlers.keyUp.call(self, event)
|
|
||||||
// })
|
|
||||||
// this.$messageInput.on('focus', function() {
|
|
||||||
// Handlers.inputFocus.call(self)
|
|
||||||
// })
|
|
||||||
// this.$messageInput.on('blur', function() {
|
|
||||||
// Handlers.inputBlur.call(self)
|
|
||||||
// })
|
|
||||||
},
|
|
||||||
addWrapper: () => {
|
|
||||||
$('body').prepend('<div id="chat-box-wrapper"></div>')
|
$('body').prepend('<div id="chat-box-wrapper"></div>')
|
||||||
},
|
},
|
||||||
render: () => {
|
render: () => {
|
||||||
|
@ -73,7 +48,18 @@ const ChatView = {
|
||||||
leaveCall: Realtime.leaveCall,
|
leaveCall: Realtime.leaveCall,
|
||||||
joinCall: Realtime.joinCall,
|
joinCall: Realtime.joinCall,
|
||||||
participants: self.participants,
|
participants: self.participants,
|
||||||
unreadMessages: self.unreadMessages
|
messages: self.messages,
|
||||||
|
unreadMessages: self.unreadMessages,
|
||||||
|
buttonClick: self.buttonClick,
|
||||||
|
videoToggleClick: self.videoToggleClick,
|
||||||
|
cursorToggleClick: self.cursorToggleClick,
|
||||||
|
soundToggleClick: self.soundToggleClick,
|
||||||
|
inputBlur: self.inputBlur,
|
||||||
|
inputFocus: self.inputFocus,
|
||||||
|
videosShowing: self.videosShowing,
|
||||||
|
cursorsShowing: self.cursorsShowing,
|
||||||
|
alertSound: self.alertSound,
|
||||||
|
handleInputMessage: self.handleInputMessage
|
||||||
}), document.getElementById('chat-box-wrapper'))
|
}), document.getElementById('chat-box-wrapper'))
|
||||||
},
|
},
|
||||||
show: () => {
|
show: () => {
|
||||||
|
@ -85,7 +71,7 @@ const ChatView = {
|
||||||
ChatView.render()
|
ChatView.render()
|
||||||
},
|
},
|
||||||
addParticipant: participant => {
|
addParticipant: participant => {
|
||||||
const p = clone(participant.attributes)
|
const p = participant.attributes ? clone(participant.attributes) : participant
|
||||||
ChatView.participants.push(p)
|
ChatView.participants.push(p)
|
||||||
ChatView.render()
|
ChatView.render()
|
||||||
},
|
},
|
||||||
|
@ -119,14 +105,13 @@ const ChatView = {
|
||||||
|
|
||||||
self.messages.push(m)
|
self.messages.push(m)
|
||||||
// TODO what is scrollMessages?
|
// TODO what is scrollMessages?
|
||||||
if (!isInitial) this.scrollMessages(200)
|
// if (!isInitial) self.scrollMessages(200)
|
||||||
self.render()
|
self.render()
|
||||||
|
|
||||||
if (!wasMe && !isInitial && this.alertSound) this.sound.play('receivechat')
|
if (!wasMe && !isInitial && self.alertSound) self.sound.play('receivechat')
|
||||||
},
|
},
|
||||||
handleInputMessage: text => {
|
handleInputMessage: text => {
|
||||||
// TODO set textarea to be empty in react
|
$(document).trigger(ChatView.events.message + '-' + self.room, [{ message: text }])
|
||||||
$(document).trigger(ChatView.events.message + '-' + this.room, [{ message: text }])
|
|
||||||
},
|
},
|
||||||
leaveConversation: () => {
|
leaveConversation: () => {
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
|
@ -147,39 +132,54 @@ const ChatView = {
|
||||||
invitationAnswered: () => {
|
invitationAnswered: () => {
|
||||||
// TODO refactor
|
// TODO refactor
|
||||||
// this.$participants.find('.participant-' + id).removeClass('pending')
|
// this.$participants.find('.participant-' + id).removeClass('pending')
|
||||||
}
|
},
|
||||||
}
|
buttonClick: () => {
|
||||||
|
const self = ChatView
|
||||||
|
if (self.isOpen) self.close()
|
||||||
|
else if (!self.isOpen) self.open()
|
||||||
|
},
|
||||||
|
close: () => {
|
||||||
|
this.isOpen = false
|
||||||
|
|
||||||
var Handlers = {
|
// TODO how to do focus with react
|
||||||
buttonClick: function() {
|
// this.$messageInput.blur()
|
||||||
if (this.isOpen) this.close()
|
|
||||||
else if (!this.isOpen) this.open()
|
$(document).trigger(ChatView.events.closeTray)
|
||||||
|
ChatView.render()
|
||||||
|
},
|
||||||
|
open: () => {
|
||||||
|
ChatView.unreadMessages = 0
|
||||||
|
this.isOpen = true
|
||||||
|
|
||||||
|
// TODO how to do focus with react
|
||||||
|
// this.$messageInput.focus()
|
||||||
|
// TODO reimplement scrollMessages
|
||||||
|
// this.scrollMessages(0)
|
||||||
|
|
||||||
|
$(document).trigger(ChatView.events.openTray)
|
||||||
|
ChatView.render()
|
||||||
},
|
},
|
||||||
videoToggleClick: function() {
|
videoToggleClick: function() {
|
||||||
this.$videoToggle.toggleClass('active')
|
const self = ChatView
|
||||||
this.videosShowing = !this.videosShowing
|
self.videosShowing = !self.videosShowing
|
||||||
$(document).trigger(this.videosShowing ? ChatView.events.videosOn : ChatView.events.videosOff)
|
$(document).trigger(self.videosShowing ? ChatView.events.videosOn : ChatView.events.videosOff)
|
||||||
|
ChatView.render()
|
||||||
},
|
},
|
||||||
cursorToggleClick: function() {
|
cursorToggleClick: function() {
|
||||||
this.$cursorToggle.toggleClass('active')
|
const self = ChatView
|
||||||
this.cursorsShowing = !this.cursorsShowing
|
self.cursorsShowing = !self.cursorsShowing
|
||||||
$(document).trigger(this.cursorsShowing ? ChatView.events.cursorsOn : ChatView.events.cursorsOff)
|
$(document).trigger(self.cursorsShowing ? ChatView.events.cursorsOn : ChatView.events.cursorsOff)
|
||||||
|
ChatView.render()
|
||||||
},
|
},
|
||||||
soundToggleClick: function() {
|
soundToggleClick: function() {
|
||||||
|
const self = ChatView
|
||||||
this.alertSound = !this.alertSound
|
this.alertSound = !this.alertSound
|
||||||
this.$soundToggle.toggleClass('active')
|
ChatView.render()
|
||||||
},
|
},
|
||||||
keyUp: function(event) {
|
inputFocus: () => {
|
||||||
switch (event.which) {
|
|
||||||
case 13: // enter
|
|
||||||
Private.handleInputMessage.call(this)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
|
||||||
inputFocus: function() {
|
|
||||||
$(document).trigger(ChatView.events.inputFocus)
|
$(document).trigger(ChatView.events.inputFocus)
|
||||||
},
|
},
|
||||||
inputBlur: function() {
|
inputBlur: () => {
|
||||||
$(document).trigger(ChatView.events.inputBlur)
|
$(document).trigger(ChatView.events.inputBlur)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,34 +200,10 @@ var Handlers = {
|
||||||
// this.$participants.find('.participant').removeClass('pending')
|
// this.$participants.find('.participant').removeClass('pending')
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// ChatView.prototype.addParticipant = function(participant) {
|
|
||||||
// this.participants.add(participant)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ChatView.prototype.removeParticipant = function(username) {
|
|
||||||
// var p = this.participants.find(p => p.get('username') === username)
|
|
||||||
// if (p) {
|
|
||||||
// this.participants.remove(p)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ChatView.prototype.removeParticipants = function() {
|
// ChatView.prototype.removeParticipants = function() {
|
||||||
// this.participants.remove(this.participants.models)
|
// this.participants.remove(this.participants.models)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ChatView.prototype.open = function() {
|
|
||||||
// this.$container.css({
|
|
||||||
// right: '0'
|
|
||||||
// })
|
|
||||||
// this.$messageInput.focus()
|
|
||||||
// this.isOpen = true
|
|
||||||
// this.unreadMessages = 0
|
|
||||||
// this.$unread.hide()
|
|
||||||
// this.scrollMessages(0)
|
|
||||||
// $(document).trigger(ChatView.events.openTray)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ChatView.prototype.addMessage = function(message, isInitial, wasMe) {
|
// ChatView.prototype.addMessage = function(message, isInitial, wasMe) {
|
||||||
// this.messages.add(message)
|
// this.messages.add(message)
|
||||||
// Private.addMessage.call(this, message, isInitial, wasMe)
|
// Private.addMessage.call(this, message, isInitial, wasMe)
|
||||||
|
@ -247,15 +223,6 @@ var Handlers = {
|
||||||
// this.$messages.empty()
|
// this.$messages.empty()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// ChatView.prototype.close = function() {
|
|
||||||
// this.$container.css({
|
|
||||||
// right: '-300px'
|
|
||||||
// })
|
|
||||||
// this.$messageInput.blur()
|
|
||||||
// this.isOpen = false
|
|
||||||
// $(document).trigger(ChatView.events.closeTray)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ChatView.prototype.remove = function() {
|
// ChatView.prototype.remove = function() {
|
||||||
// this.$button.off()
|
// this.$button.off()
|
||||||
// this.$container.remove()
|
// this.$container.remove()
|
||||||
|
|
|
@ -4,16 +4,40 @@ import Participant from './Participant'
|
||||||
import Message from './Message'
|
import Message from './Message'
|
||||||
|
|
||||||
class MapChat extends Component {
|
class MapChat extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
messageText: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange = key => e => {
|
||||||
|
this.setState({
|
||||||
|
[key]: e.target.value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleTextareaKeyUp = e => {
|
||||||
|
if (e.which === 13) {
|
||||||
|
e.preventDefault()
|
||||||
|
const text = this.state.messageText
|
||||||
|
this.props.handleInputMessage(text)
|
||||||
|
this.setState({ messageText: '' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
const rightOffset = this.props.isOpen ? '-300px' : '0'
|
const rightOffset = this.props.isOpen ? '-300px' : '0'
|
||||||
|
const { videosShowing, cursorsShowing, alertSound } = this.props
|
||||||
return (
|
return (
|
||||||
<div className="chat-box"
|
<div className="chat-box"
|
||||||
style={{ right: rightOffset }}
|
style={{ right: rightOffset }}
|
||||||
>
|
>
|
||||||
<div className="junto-header">
|
<div className="junto-header">
|
||||||
PARTICIPANTS
|
PARTICIPANTS
|
||||||
<div className="video-toggle" />
|
<div className={`video-toggle ${videosShowing ? 'active' : ''}`} />
|
||||||
<div className="cursor-toggle" />
|
<div className={`cursor-toggle ${cursorsShowing ? 'active' : ''}`} />
|
||||||
</div>
|
</div>
|
||||||
<div className="participants">
|
<div className="participants">
|
||||||
<div className="conversation-live">
|
<div className="conversation-live">
|
||||||
|
@ -25,17 +49,31 @@ class MapChat extends Component {
|
||||||
JOIN
|
JOIN
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{this.props.participants.map(participant => {
|
||||||
|
return <Participant key={participant.id} {...participant} />
|
||||||
|
})}
|
||||||
</div>
|
</div>
|
||||||
<div className="chat-header">
|
<div className="chat-header">
|
||||||
CHAT
|
CHAT
|
||||||
<div className="sound-toggle"></div>
|
<div className={`sound-toggle ${alertSound ? 'active' : ''}`}></div>
|
||||||
</div>
|
</div>
|
||||||
<div className="chat-button">
|
<div className="chat-button">
|
||||||
<div className="tooltips">Chat</div>
|
<div className="tooltips">Chat</div>
|
||||||
<Unread count={this.props.unreadMessages} />
|
<Unread count={this.props.unreadMessages} />
|
||||||
</div>
|
</div>
|
||||||
<div className="chat-messages"></div>
|
<div className="chat-messages">
|
||||||
<textarea className="chat-input" placeholder="Send a message..." />
|
{this.props.messages.map(message => {
|
||||||
|
return <Message key={message.id} {...message} />
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<textarea className="chat-input"
|
||||||
|
placeholder="Send a message..."
|
||||||
|
value={this.state.messageText}
|
||||||
|
onChange={this.handleChange('messageText')}
|
||||||
|
onKeyUp={this.handleTextareaKeyUp}
|
||||||
|
onFocus={this.props.inputFocus}
|
||||||
|
onBlur={this.props.inputBlur}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue