metamaps--metamaps/frontend/src/components/MapChat/index.js

139 lines
3.9 KiB
JavaScript
Raw Normal View History

import React, { PropTypes, Component } from 'react'
2016-12-19 00:08:48 -05:00
import Unread from './Unread'
import Participant from './Participant'
import Message from './Message'
class MapChat extends Component {
2016-12-19 00:41:31 -05:00
constructor(props) {
super(props)
this.state = {
2016-12-19 15:52:05 -05:00
unreadMessages: 0,
2016-12-19 14:57:53 -05:00
open: false,
2016-12-19 17:09:49 -05:00
messageText: '',
alertSound: true, // whether to play sounds on arrival of new messages or not
cursorsShowing: true,
videosShowing: true
2016-12-19 00:41:31 -05:00
}
}
2016-12-19 15:52:05 -05:00
close = () => {
this.setState({open: false})
this.props.onClose()
}
open = () => {
this.setState({open: true, unreadMessages: 0})
this.props.onOpen()
}
newMessage = () => {
if (!this.state.open) this.setState({ unreadMessages: this.state.unreadMessages + 1 })
}
2016-12-19 14:57:53 -05:00
toggleDrawer = () => {
2016-12-19 15:52:05 -05:00
if (this.state.open) this.close()
else if (!this.state.open) this.open()
2016-12-19 14:57:53 -05:00
}
2016-12-19 17:09:49 -05:00
toggleAlertSound = () => {
this.setState({alertSound: !this.state.alertSound})
this.props.soundToggleClick()
}
toggleCursorsShowing = () => {
this.setState({cursorsShowing: !this.state.cursorsShowing})
this.props.cursorToggleClick()
}
toggleVideosShowing = () => {
this.setState({videosShowing: !this.state.videosShowing})
this.props.videoToggleClick()
}
2016-12-19 00:41:31 -05:00
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: '' })
}
}
2016-12-19 00:08:48 -05:00
render = () => {
2016-12-19 14:57:53 -05:00
const rightOffset = this.state.open ? '0' : '-300px'
2016-12-19 17:09:49 -05:00
const { videosShowing, cursorsShowing, alertSound, unreadMessages } = this.state
return (
<div className="chat-box"
style={{ right: rightOffset }}
>
<div className="junto-header">
PARTICIPANTS
2016-12-19 17:09:49 -05:00
<div onClick={this.toggleVideosShowing} className={`video-toggle ${videosShowing ? '' : 'active'}`} />
<div onClick={this.toggleCursorsShowing} className={`cursor-toggle ${cursorsShowing ? '' : 'active'}`} />
</div>
<div className="participants">
2016-12-19 00:08:48 -05:00
<div className="conversation-live">
LIVE
<span className="call-action leave" onClick={this.props.leaveCall}>
LEAVE
</span>
<span className="call-action join" onClick={this.props.joinCall}>
JOIN
</span>
2016-12-19 00:08:48 -05:00
</div>
2016-12-19 00:41:31 -05:00
{this.props.participants.map(participant => {
return <Participant key={participant.id} {...participant} />
})}
</div>
<div className="chat-header">
CHAT
2016-12-19 17:09:49 -05:00
<div onClick={this.toggleAlertSound} className={`sound-toggle ${alertSound ? '' : 'active'}`}></div>
</div>
2016-12-19 14:57:53 -05:00
<div className="chat-button" onClick={this.toggleDrawer}>
<div className="tooltips">Chat</div>
2016-12-19 15:52:05 -05:00
<Unread count={unreadMessages} />
</div>
2016-12-19 00:41:31 -05:00
<div className="chat-messages">
{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>
)
}
}
MapChat.propTypes = {
2016-12-19 14:57:53 -05:00
onOpen: PropTypes.func,
onClose: PropTypes.func,
leaveCall: PropTypes.func,
joinCall: PropTypes.func,
2016-12-19 17:09:49 -05:00
videoToggleClick: PropTypes.func,
cursorToggleClick: PropTypes.func,
soundToggleClick: PropTypes.func,
participants: PropTypes.arrayOf(PropTypes.shape({
2016-12-18 23:24:57 -05:00
color: PropTypes.string, // css color
id: PropTypes.number,
image: PropTypes.string, // image url
self: PropTypes.bool,
2016-12-18 23:24:57 -05:00
username: PropTypes.string
}))
}
export default MapChat