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

96 lines
2.7 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 = {
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: '' })
}
}
2016-12-19 00:08:48 -05:00
render = () => {
const rightOffset = this.props.isOpen ? '-300px' : '0'
2016-12-19 00:41:31 -05:00
const { videosShowing, cursorsShowing, alertSound } = this.props
return (
<div className="chat-box"
style={{ right: rightOffset }}
>
<div className="junto-header">
PARTICIPANTS
2016-12-19 00:41:31 -05:00
<div className={`video-toggle ${videosShowing ? 'active' : ''}`} />
<div 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 00:41:31 -05:00
<div className={`sound-toggle ${alertSound ? 'active' : ''}`}></div>
</div>
<div className="chat-button">
<div className="tooltips">Chat</div>
2016-12-18 23:24:57 -05:00
<Unread count={this.props.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 00:08:48 -05:00
isOpen: PropTypes.bool,
leaveCall: PropTypes.func,
joinCall: 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