import React from 'react'; import styled from 'styled-components' import RaisedButton from 'material-ui/RaisedButton'; import TextField from 'material-ui/TextField'; import FloatingActionButton from 'material-ui/FloatingActionButton'; import FontIcon from 'material-ui/FontIcon'; import Avatar from 'material-ui/Avatar'; import Divider from 'material-ui/Divider'; import { List, ListItem } from 'material-ui/List'; import Overlay from './Overlay'; const ChatWindow = styled.div` position: relative; display: inline-flex; flex-direction: column; justify-content: flex-end; height: 100%; width: 420px; box-sizing: border-box; ` const ChatPanel = styled.div` position: relative; display: inline-flex; flex-direction: column; justify-content: flex-end; height: 100%; width: 100%; box-sizing: border-box; z-index: 1; ` const Header = styled.div` display: flex; align-items: center; justify-content: space-between; margin: 0 20px ; z-index: 1; color: #fafafa !important; border-bottom: 1px solid; ` const Title = styled.p` text-align: center; font-size: 24px; ` const NoDots = styled.div` hr { visibility: hidden; } ` const OutputText = styled.div` white-space: normal !important; word-break: break-all !important; overflow: initial !important; width: 100%; height: auto !important; color: #fafafa !important; ` const InputPanel = styled.div` display: flex; align-items: center; padding: 20px; align-self: center; border-top: 1px solid #fafafa; ` const ChatroomImage = styled.img` position: absolute; top: 0; width: 100%; ` const Scrollable = styled.div` height: 100%; overflow: auto; ` export default class Chatroom extends React.Component { constructor(props, context) { super(props, context) const { chatHistory } = props this.state = { chatHistory, input: '' } this.onInput = this.onInput.bind(this) this.onSendMessage = this.onSendMessage.bind(this) this.onMessageReceived = this.onMessageReceived.bind(this) this.updateChatHistory = this.updateChatHistory.bind(this) this.scrollChatToBottom = this.scrollChatToBottom.bind(this) } componentDidMount() { this.props.registerHandler(this.onMessageReceived) this.scrollChatToBottom() } componentDidUpdate() { this.scrollChatToBottom() } componentWillUnmount() { this.props.unregisterHandler() } onInput(e) { this.setState({ input: e.target.value }) } onSendMessage() { if (!this.state.input) return this.props.onSendMessage(this.state.input, (err) => { if (err) return console.error(err) return this.setState({ input: '' }) }) } onMessageReceived(entry) { console.log('onMessageReceived:', entry) this.updateChatHistory(entry) } updateChatHistory(entry) { this.setState({ chatHistory: this.state.chatHistory.concat(entry) }) } scrollChatToBottom() { this.panel.scrollTo(0, this.panel.scrollHeight) } render() { return (