-
Couldn't load subscription status.
- Fork 17
Ocelots - Kelly T #7
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
95a698a
054f244
45900e3
7ec84be
bcc4d75
52e473e
3ba2ac9
c6afce9
7dbe769
3e950aa
308ce2d
93256ca
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,42 @@ | ||
| import React from 'react'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import TimeStamp from './TimeStamp.js'; | ||
|
|
||
| const ChatEntry = (props) => { | ||
|
|
||
| const onLikeButtonClick = () => { | ||
| const updatedChatEntry = { | ||
| id: props.id, | ||
| sender: props.sender, | ||
| body: props.body, | ||
| timeStamp: props.timeStamp, | ||
| liked: !props.liked, | ||
| }; | ||
| props.onUpdate(updatedChatEntry); | ||
| }; | ||
|
Comment on lines
+8
to
+17
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 heartColor = props.liked ? '❤️' : '🤍'; | ||
|
|
||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <h2 className="entry-name">{props.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>{props.body}</p> | ||
| <p className="entry-time">{<TimeStamp time={props.timeStamp}/>}</p> | ||
| <button className="like" onClick={onLikeButtonClick}>{heartColor}</button> | ||
| </section> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ChatEntry.propTypes = { | ||
| //Fill with correct proptypes | ||
| id: PropTypes.number, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool, | ||
| onUpdate: PropTypes.func | ||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React from 'react'; | ||
| import './ChatLog.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import ChatEntry from './ChatEntry.js'; | ||
|
|
||
| const ChatLog = (props) => { | ||
| const entries = props.entries.map((entry, index) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={index} | ||
|
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. If the messages all have unique ids, then we could use those values for the |
||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onUpdate={props.onUpdateEntry} | ||
| /> | ||
| ); | ||
| }); | ||
| return( | ||
| <section className="chat-log"> | ||
| {entries} | ||
| </section> | ||
| ); | ||
|
|
||
| }; | ||
|
|
||
| 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, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool, | ||
| })), | ||
| onUpdateEntry: PropTypes.func | ||
| }; | ||
|
|
||
|
|
||
| export default ChatLog; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import '../App.css'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const HeartInfo = (props) => { | ||
| return ( | ||
| <section> | ||
| <span id="heartWidget" className="widget"> | ||
| {props.likesCount} ❤️s | ||
| </span> | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| HeartInfo.propTypes = { | ||
| likesCount: PropTypes.number | ||
| }; | ||
|
|
||
| export default HeartInfo; |
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
chatEntryDatadata we should avoid holding an extra 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: