import classnames from 'classnames'
import React from 'react'
import { Message as MessageType } from '../actions/ChatActions'
import { TextMessage } from '../actions/PeerActions'
import Input from './Input'
export interface MessageProps {
message: MessageType
}
function Message (props: MessageProps) {
const { message } = props
return (
{message.image && (
)}
{message.message}
)
}
export interface ChatProps {
visible: boolean
messages: MessageType[]
onClose: () => void
sendMessage: (message: TextMessage) => void
}
export default class Chat extends React.PureComponent {
chatHistoryRef = React.createRef()
scrollToBottom = () => {
const chatHistoryRef = this.chatHistoryRef.current!
chatHistoryRef.scrollTop = chatHistoryRef.scrollHeight
}
componentDidMount () {
this.scrollToBottom()
}
componentDidUpdate () {
this.scrollToBottom()
}
render () {
const { messages, sendMessage } = this.props
return (
{messages.length ? (
messages.map((message, i) => (
{message.userId === 'You' ? (
{message.userId}
{message.image ? (

) : (
)}
) : (
{message.image ? (

) : (
)}
{message.userId}
)}
))
) : (
)}
)
}
}