- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
AC2 - Dalia #1
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?
AC2 - Dalia #1
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,50 @@ | ||
| import React from 'react'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import TimeStamp from './TimeStamp'; | ||
|  | ||
| const ChatEntry = ({ | ||
| id, | ||
| sender, | ||
| body, | ||
| timeStamp, | ||
| liked, | ||
| onUpdateChatHeart, | ||
| }) => { | ||
| const likeOrUnlikeMessage = () => { | ||
| const updatedMessage = { | ||
| id: id, | ||
| sender: sender, | ||
| body: body, | ||
| timeStamp: timeStamp, | ||
| liked: !liked, | ||
| }; | ||
| onUpdateChatHeart(updatedMessage); | ||
| }; | ||
| 
      Comment on lines
    
      +13
     to 
      +22
    
   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. I would consider passing the  This made me think of a related concept in secure design for APIs. Imagine we had an API for creating and updating messages, and it has an endpoint  | ||
| const heartShape = liked ? '❤️' : '🤍'; | ||
|  | ||
| const ChatEntry = (props) => { | ||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <div className="chat-entry local" id={id}> | ||
| <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 className="like" onClick={likeOrUnlikeMessage}> | ||
| {heartShape} | ||
| </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, | ||
| onUpdateChatHeart: PropTypes.func.isRequired, | ||
| }; | ||
|  | ||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import React from 'react'; | ||
| import './ChatLog.css'; | ||
| import ChatEntry from './ChatEntry'; | ||
| import PropTypes from 'prop-types'; | ||
|  | ||
| const chatLog = ({ entries, onUpdateChatHeart }) => { | ||
| const chatEntries = entries.map((entry) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={entry.id} | ||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onUpdateChatHeart={onUpdateChatHeart} | ||
| /> | ||
| ); | ||
| }); | ||
|  | ||
| return <section>{chatEntries}</section>; | ||
| }; | ||
|  | ||
| export default chatLog; | ||
|  | ||
| chatLog.propTypes = { | ||
| entries: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| 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. Really nice use of PropTypes. | ||
| id: PropTypes.number.isRequired, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool.isRequired, | ||
| }) | ||
| ), | ||
| onUpdateChatHeart: PropTypes.func.isRequired, | ||
| }; | ||
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 the liked status of a message lives in the
chatEntriesdata we should avoid holding an extra variable or piece of state that we need to manually keep in sync. We can use a higher order function likearray.reduceto take our list of messages and reduce it down to a single value: