Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/src/components/Chat/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let socket;
const Chat = ({ location }) => {
const [name, setName] = useState('');
const [room, setRoom] = useState('');
const [users, setUsers] = useState('');
const [users, setUsers] = useState([]);
const [message, setMessage] = useState('');
const [messages, setMessages] = useState([]);

Expand All @@ -33,7 +33,7 @@ const Chat = ({ location }) => {
alert(error);
}
});
}, [ENDPOINT, location.search]);
}, [location.search]);

useEffect(() => {
socket.on('message', message => {
Expand All @@ -43,7 +43,7 @@ const Chat = ({ location }) => {
socket.on("roomData", ({ users }) => {
setUsers(users);
});
}, []);
}, [messages]);

const sendMessage = (event) => {
event.preventDefault();
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ const Input = ({ setMessage, sendMessage, message }) => (
placeholder="Type a message..."
value={message}
onChange={({ target: { value } }) => setMessage(value)}
onKeyPress={event => event.key === 'Enter' ? sendMessage(event) : null}
/>
<button className="sendButton" onClick={e => sendMessage(e)}>Send</button>
<button className="sendButton" onClick={()=> sendMessage(message)}>Send</button>
</form>
)

Expand Down
72 changes: 42 additions & 30 deletions client/src/components/TextContainer/TextContainer.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
import React from 'react';
import React from "react";

import onlineIcon from '../../icons/onlineIcon.png';
import onlineIcon from "../../icons/onlineIcon.png";

import './TextContainer.css';
import "./TextContainer.css";

const TextContainer = ({ users }) => (
<div className="textContainer">
<div>
<h1>Realtime Chat Application <span role="img" aria-label="emoji">💬</span></h1>
<h2>Created with React, Express, Node and Socket.IO <span role="img" aria-label="emoji">❤️</span></h2>
<h2>Try it out right now! <span role="img" aria-label="emoji">⬅️</span></h2>
</div>
{
users
? (
<div>
<h1>People currently chatting:</h1>
<div className="activeContainer">
<h2>
{users.map(({name}) => (
<div key={name} className="activeItem">
{name}
<img alt="Online Icon" src={onlineIcon}/>
</div>
))}
</h2>
</div>
</div>
)
: null
}
</div>
<div className="textContainer">
<div>
<h1>
Realtime Chat Application{" "}
<span role="img" aria-label="emoji">
💬
</span>
</h1>
<h2>
Created with React, Express, Node and Socket.IO{" "}
<span role="img" aria-label="emoji">
❤️
</span>
</h2>
<h2>
Try it out right now!{" "}
<span role="img" aria-label="emoji">
⬅️
</span>
</h2>
</div>
{users.length !== 0 && (
<div>
<h1>People currently chatting:</h1>
<div className="activeContainer">
<h2>
{users.map(({ name }) => (
<div key={name} className="activeItem">
{name}
<img alt="Online Icon" src={onlineIcon} />
</div>
))}
</h2>
</div>
</div>
)}
{users.length === 0 && <span>Nobody is chatting right now</span>}
</div>
);

export default TextContainer;
export default TextContainer;
Loading