Skip to content

Cleaning code #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -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([]);

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

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

const sendMessage = (event) => {
event.preventDefault();
3 changes: 1 addition & 2 deletions client/src/components/Input/Input.js
Original file line number Diff line number Diff line change
@@ -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>
)

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