diff --git a/src/components/Chat.js b/src/components/Chat.js index b59deeb..2fe8e71 100644 --- a/src/components/Chat.js +++ b/src/components/Chat.js @@ -1,6 +1,6 @@ import React from 'react' import { Form, Row, Col, Button, Card, ListGroup, Image } from 'react-bootstrap' -//import ScrollToBottom from 'react-scroll-to-bottom' +import SingleMessage from './SingleMessage' import userImage from '../assets/default-user-image.png' import uuid from 'uuid' @@ -33,7 +33,7 @@ class Chat extends React.Component { socket.on('connect', () => { console.log('Connected!') - this.setState({ user: { socketId: socket.id } }) + this.setState({ user: { socketId: socket.id, userImage } }) }) } @@ -63,29 +63,30 @@ class Chat extends React.Component { } handleSubmit(e) { e.preventDefault() - const message = { userId: socket.id, id: uuid(), text: this.state.text } + const message = { socketId: socket.id, id: uuid(), text: this.state.text } const messages = this.state.messages.concat(message) this.setState({ messages, text: '' }) socket.emit('message', message) } + getStatus() { + console.log('this is the status') + } render() { return ( - {this.state.messages.map(msg => ( - - { + return ( + - {msg.userId}: {msg.text} - - ))} + ) + })}
{ @@ -117,11 +118,18 @@ class Chat extends React.Component { - {this.state.typing ? ( -
Someone is typing...
- ) : ( -
- )} + + + + {this.state.typing ? 'Someone is typing...' : ''} + + + {this.state.user.socketId} + + ) diff --git a/src/components/SingleMessage.js b/src/components/SingleMessage.js new file mode 100644 index 0000000..4585cec --- /dev/null +++ b/src/components/SingleMessage.js @@ -0,0 +1,24 @@ +import React from 'react' +import { ListGroup, Image } from 'react-bootstrap' +const SingleMessage = props => { + const { user, socketId, text } = props + + if (user.socketId === socketId) + return ( + +
{text}
+
+ ) + return ( + + + {user.socketId}: {text} + + ) +} + +export default SingleMessage