-
Notifications
You must be signed in to change notification settings - Fork 117
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
finished forgot to commit oh no #103
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job on react-chatlog! I do recommend making frequent, small commits with descriptive messages so that it's easier to understand your git history
Let me know if you have questions about my code review comments.
{ | ||
"python.testing.unittestArgs": [ | ||
"-v", | ||
"-s", | ||
".", | ||
"-p", | ||
"*test.py" | ||
], | ||
"python.testing.pytestEnabled": false, | ||
"python.testing.unittestEnabled": true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are your settings for your own vscode, you don't need to add/commit this file
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a blank line was added to the file and then added/committed. we want to avoid bringing in unnecessary changes to a PR. In the future, you can just unstage the change so it doesn't get committed.
import chatMessages from './data/messages.json'; | ||
import ChatLog from './components/ChatLog'; | ||
import { useState } from 'react'; | ||
import Chats from './data/messages.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Chats
is a constant variable, you can name it with all cap letters like CHATS
or you could just call it chats
, but it's unusual to see a variable name begin with a capital letter.
|
||
const App = () => { | ||
const [chatMessages, setChatMessages] = useState(Chats); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice job setting up state for chat messages.
|
||
const App = () => { | ||
const [chatMessages, setChatMessages] = useState(Chats); | ||
|
||
const heartClick = (entryToUpdate) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than receiving a new entry with it's like status already changed here, rewrite this method to accept only an id. The logic about how to copy the message and change the liked status would be better if it was written in App.js, since the state must have all the information necessary to make a new message.
const heartClick = id => {
const entries = chatMessageData.map(message => {
if (message.id === id){
return {...message, liked: !message.liked};
}
else {
return message;
}
});
setChatMessages(entries);
}
const ChatEntry = ({id, sender, body, timeStamp, liked, heartClick}) => { | ||
|
||
const clickLikedHeart = () => { | ||
heartClick( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment in app.js about only passing in an id (instead of an entire chat object) into heartClick
.
That would make this method look like:
const clickLikedHeart = () => {
heartClick(id);
};
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
id: PropTypes.number.isRequired, | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool, | ||
heartClick: PropTypes.func | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 PropTypes look good!
|
||
const ChatEntry = (props) => { | ||
return ( | ||
<div className="chat-entry local"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it is an optional enhancement to make the local and remote messages display on different sides of the screen, I did want to plant the seed of how you could do that.
If you look in ChatEntry.css, there are 2 classes called 'local' and 'remote'. Right now, on line 18 we've hardcoded one of the class names to be 'local'. But what if we checked to see if the sender
=== 'Vladimir' and assign a variable to be 'remote' and if it wasn't Vladimir, then the variable would be 'local'.
const senderClass = sender === 'Vladimir' ? 'remote' : 'local';
Then you could use senderClass on line 18 to set the class depending on the sender, like:
<div className={`chat-entry ${senderClass}`}>
const getChatLog = () => { | ||
return entries.map((entry) => { | ||
return ( | ||
<ChatEntry | ||
key= {entry.id} | ||
id= {entry.id} | ||
sender= {entry.sender} | ||
body= {entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} | ||
heartClick= {heartClick} | ||
/> | ||
); | ||
}); | ||
}; | ||
return ( | ||
<div> | ||
{getChatLog(entries)} | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, instead of writing a method getChatLogs
to reference the return value from calling map() on entries, it's more common to directly iterate over the chat entries in your component like this without using a variable:
const ChatLog = ({entries, heartClick}) => {
return (
<div>
{entries.map((entry) => (
<ChatEntry
key={entry.id}
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}
heartClick={heartClick}
/>
))}
</div>
)
};
key= {entry.id} | ||
id= {entry.id} | ||
sender= {entry.sender} | ||
body= {entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} | ||
heartClick= {heartClick} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent whitespaces after = needs to be tidied up before opening a PR
liked: PropTypes.bool, | ||
heartClick: PropTypes.func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing .isRequired
for these last 2 PropTypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait! i remember hearing in the wrap-up session that tests were failing unless you removed .isRequired. Disregard this comment
No description provided.