-
Notifications
You must be signed in to change notification settings - Fork 17
AC2-Ocelots-Elaine(Si Ok) Sohn #4
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
e2b4720
89b28ae
1a365db
f5bac26
d372462
2241835
f0df86a
aedc77c
c360927
184be83
31f86b1
1732c0c
6981944
679de7b
f102b0a
2bc8275
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| asset-manifest.json,1675364990843,dece47109c0ca1e64c1b5e94618f11bfa9d69585a6a8c297d281df22928b0ec7 | ||
| manifest.json,1675364988458,5fb9316df9fcb631af8259f9a91b476804b4d68258e1c4144017c018f2b63aa3 | ||
| index.html,1675364990843,d7d5a09cf7feab5366cf2d0dbe3c9989a15fe8749268439a902cd564b3e09f40 | ||
| favicon.ico,1675364988457,b72f7455f00e4e58792d2bca892abb068e2213838c0316d6b7a0d6d16acd1955 | ||
| static/js/main.95edea91.js.LICENSE.txt,1675364990845,65c6ecb6192f97a7b3e674b68ee6129941ddc83db480b46ce95eaea24ff40121 | ||
| static/css/main.a6e8f088.css.map,1675364990845,12abce3ad8340f964b204829f9fb593ab92dd96d24cd074a8f1380636efd11bb | ||
| static/css/main.a6e8f088.css,1675364990845,76e1ca20fd6535a8bba07534184f8a7a6eba7698a209b025cca6fb5c763df7fb | ||
| static/js/main.95edea91.js,1675364990845,11186382d3ddf88d44e43905aeb9c485a2e600a7316fd34fc3241184d679ea57 | ||
| static/js/main.95edea91.js.map,1675364990845,c45e64aadb10424bf980a4a465c3c7225448e3129425eca8eb25e3486b390fd8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "projects": { | ||
| "default": "react-chatlog" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "hosting": { | ||
| "public": "build", | ||
| "ignore": [ | ||
| "firebase.json", | ||
| "**/.*", | ||
| "**/node_modules/**" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ describe('Wave 03: clicking like button and rendering App', () => { | |
| // Arrange | ||
| const { container } = render(<App />) | ||
| const buttons = container.querySelectorAll('button.like') | ||
| console.log(buttons) | ||
|
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. Gentle reminder that we want to take a scan through our files and remove diagnostic/debugging code before opening PRs. |
||
| const firstButton = buttons[0] | ||
| const lastButton = buttons[buttons.length - 1] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,43 @@ | ||
| import React from 'react'; | ||
| import '../App.css'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import TimeStamp from './TimeStamp'; | ||
|
|
||
| const ChatEntry = ({id, sender, body, timeStamp, liked, onUpdate, color, location}) => { | ||
|
|
||
| const toggleHeart = () => { | ||
| return onUpdate({ | ||
| id, | ||
| sender, | ||
| body, | ||
| timeStamp, | ||
| liked: !liked, | ||
| }) | ||
| }; | ||
|
Comment on lines
+9
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 ChatEntry = (props) => { | ||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <div className={`chat-entry ${location}`}> | ||
| <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 className={`${color}`}>{body}</p> | ||
| <p className="entry-time"> | ||
| <TimeStamp time = {timeStamp}/></p> | ||
| <button className="like" onClick={toggleHeart}>{liked? '❤️' : '🤍'}</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, | ||
| color: PropTypes.string, | ||
| location: PropTypes.string, | ||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import ChatEntry from './ChatEntry'; | ||
| import './ChatLog.css'; | ||
|
|
||
| const ChatLog = ({entries, onUpdate, localColor, remoteColor, localSender}) => { | ||
| return <ul className="chat-log"> | ||
| {entries.map((entry) => ( | ||
|
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. It is a little hard to understand the structure of the JSX with the mapping embedded here, I suggest pulling the mapping out and storing the result of it in a variable that you can then place in the JSX. |
||
| (entry.sender === localSender)? | ||
| <ChatEntry | ||
| // key={entry.id} | ||
| key={entry.timeStamp} | ||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onUpdate = {onUpdate} | ||
| color={localColor} | ||
| location='local' | ||
| /> : | ||
| <ChatEntry | ||
| // key={entry.id} | ||
| key={entry.timeStamp} | ||
| id={entry.id} | ||
| sender={entry.sender} | ||
| body={entry.body} | ||
| timeStamp={entry.timeStamp} | ||
| liked={entry.liked} | ||
| onUpdate = {onUpdate} | ||
| color={remoteColor} | ||
| location='remote' | ||
| /> | ||
|
Comment on lines
+9
to
+33
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. There's a lot of duplication between the 2 ChatEntry components, we could create a couple variables above where we create the let color = remoteColor
let location = 'remote'
if (entry.sender === localSender) {
color = localColor
location = 'local'
}
<ChatEntry
// key={entry.id}
key={entry.timeStamp}
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}
onUpdate = {onUpdate}
color={color}
location={location}
/> |
||
| ))} | ||
| </ul> | ||
| }; | ||
|
|
||
| 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, | ||
| }) | ||
| ).isRequired, | ||
| onUpdate: PropTypes.func, | ||
| localColor: PropTypes.string, | ||
| remoteColor: PropTypes.string, | ||
| localSender: PropTypes.string, | ||
| }; | ||
|
|
||
| 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.
Since the liked status of a message lives in the
chatMessagesdata we should avoid holding an extra piece of state that we need to manually keep in sync. We can removelikesCountdeclared on line 25 and use a higher order function likearray.reduceto take our list of messages and reduce it down to a single value (our like count).