-
Notifications
You must be signed in to change notification settings - Fork 111
React Chat Log - HW - Sea Turtles #91
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,48 @@ | ||
| import React from 'react'; | ||
| import './ChatEntry.css'; | ||
| import TimeStamp from './TimeStamp'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ChatEntry = (props) => { | ||
| const ChatEntry = ({ id, sender, body, timeStamp, liked, onUpdate }) => { | ||
| //Brains | ||
| const handleChangeHeart = () => { | ||
| const updatedEntry = { | ||
| id: id, | ||
| sender: sender, | ||
| body: body, | ||
| timeStamp: timeStamp, | ||
| liked: !liked, | ||
| }; | ||
| onUpdate(updatedEntry); | ||
| }; | ||
|
|
||
| //Beauty | ||
| const renderHeart = () => { | ||
| return liked ? '❤️' : '🤍'; | ||
| }; | ||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <h2 className="entry-name">{sender}</h2> | ||
| <section className="entry-bubble"> | ||
| <p>Replace with body of ChatEntry</p> | ||
| <p className="entry-time">Replace with TimeStamp component</p> | ||
| <button className="like">🤍</button> | ||
| <p>{body}</p> | ||
| <p className="entry-time"> | ||
| <TimeStamp time={timeStamp} /> | ||
| </p> | ||
| <button onClick={handleChangeHeart} className="like"> | ||
| {renderHeart()} | ||
| </button> | ||
| </section> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| 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.isRequired, | ||
|
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. The original prop types that the test is looking for are sender, body, and timeStamp. If you added your own you can either make them not required or update the test to account for the added prop types. |
||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React from 'react'; | ||
| import ChatEntry from './ChatEntry'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ChatLog = ({ entries, update }) => { | ||
| return entries.map((entry) => { | ||
| //Mapping each entry of chatMessages array to a chatEntry react component | ||
| return ( | ||
| <ChatEntry | ||
| key={entry.id} /* //Look up react keyError */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could use the index from return entries.map((entry , i) => ...
<ChatEntry
key={i}... |
||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onUpdate={update} | ||
| /> | ||
| ); | ||
| }); | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| //Fill with correct proptypes | ||
| entries: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
| update: PropTypes.func.isRequired, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Learn, I'm sure that you saw a console error for the update prop. Because your update prop was not in the original project you can handle this error by making the update prop a required prop or you can update the tests to look for update as well as entries. |
||
| }; | ||
| export default ChatLog; | ||
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.
good use of reduce!