Skip to content

Commit

Permalink
Add UI for Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyowen committed Nov 8, 2020
1 parent a66193c commit 6a4e8d3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1108/110409.313:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
2 changes: 2 additions & 0 deletions client/src/components/Chat/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './Chat.css';

import InfoBar from '../InfoBar/InfoBar';
import Input from '../Input/Input';
import Messages from '../Messages/Messages'

let socket;

Expand Down Expand Up @@ -53,6 +54,7 @@ const Chat = ({location}) => {
<div className="outerContainer">
<div className="container">
<InfoBar room={room}/>
<Messages messages={messages} name={name}/>
<Input message={message} setMessage={setMessage} sendMessage={sendMessage} />
</div>
</div>
Expand Down
55 changes: 55 additions & 0 deletions client/src/components/Message/Message.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.messageBox {
background: #f3f3f3;
border-radius: 20px;
padding: 5px 20px;
color: #fff;
display: inline-block;
max-width: 80%;
}
.messageText {
width: 100%;
letter-spacing: 0;
float: left;
font-size: 1.1em;
word-wrap: break-word;
}
.messageText img {
vertical-align: middle;
}
.messageContainer {
display: flex;
justify-content: flex-end;
padding: 0 5%;
margin-top: 3px;
}
.sentText {
display: flex;
align-items: center;
font-family: Helvetica;
color: #828282;
letter-spacing: 0.3px;
}
.pl-10 {
padding-left: 10px;
}
.pr-10 {
padding-right: 10px;
}
.justifyStart {
justify-content: flex-start;
}
.justifyEnd {
justify-content: flex-end;
}
.colorWhite {
color: #fff;
}
.colorDark {
color: #353535;
}
.backgroundBlue {
background: #2979ff;
}
.backgroundLight {
background: #f3f3f3;
}
33 changes: 33 additions & 0 deletions client/src/components/Message/Message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import './Message.css';

const Message = ({ message: { user, text }, name }) => {
let isSentByCurrentUser = false;

const trimmedName = name.trim().toLowerCase();

if(user === trimmedName){
isSentByCurrentUser = true;
}
return (
isSentByCurrentUser
? (
<div className="messageContainer justifyEnd">
<p className="sentText pr-10">{trimmedName}</p>
<div className="messageBox backgroundBlue">
<p className="messageText colorWhite">{text}</p>
</div>
</div>
)
: (
<div className="messageContainer justifyStart">
<div className="messageBox backgroundLight">
<p className="messageText colorDark">{text}</p>
</div>
<p className="sentText pl-10">{user}</p>
</div>
)
);
}

export default Message;
6 changes: 6 additions & 0 deletions client/src/components/Messages/Messages.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.messages {
padding: 5% 0;
overflow: auto;
flex: auto;
}

12 changes: 12 additions & 0 deletions client/src/components/Messages/Messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import ScrollToBottom from 'react-scroll-to-bottom';
import Message from '../Message/Message';
import './Messages.css';

const Messages = ({ messages, name }) => (
<ScrollToBottom>
{messages.map((message, i) => <div key={i}><Message message={message} name={name} /></div>)}
</ScrollToBottom>
)

export default Messages;

0 comments on commit 6a4e8d3

Please sign in to comment.