-
Notifications
You must be signed in to change notification settings - Fork 111
Sharks - Sana Pournaghshband #88
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 |
|---|---|---|
|
|
@@ -42,7 +42,8 @@ | |
|
|
||
| #App #heartWidget { | ||
| font-size: 1.5em; | ||
| margin: 1em | ||
| margin: 1em; | ||
| color: black | ||
| } | ||
|
|
||
| #App span { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,30 @@ | ||
| import React from 'react'; | ||
| import React, { useState } from 'react'; | ||
| import './App.css'; | ||
| import ChatEntry from './components/ChatEntry'; | ||
| import ChatLog from './components/ChatLog'; | ||
| import chatMessages from './data/messages.json'; | ||
|
|
||
| const App = () => { | ||
| // console.log(chatMessages); | ||
|
|
||
| // const [likedMap, setLikedMap] = useState({}) | ||
| const [likedCount, setLikedCount] = useState(0); | ||
|
|
||
| const addLike = () => setLikedCount(likedCount + 1); | ||
| const removeLike = () => setLikedCount(likedCount - 1); | ||
|
Comment on lines
+13
to
+14
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. Can you think of how you could combine the logic from addLike() and removeLike() into one method like updateLike()? The bodies of these 2 methods look very similar, the difference being + or - so maybe we can add some logic by passing in a boolean value updateLike = isLiked => { // your logic in here }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. Another comment about updating likedCount state with setLikedCount. When state represents something like a counter, we need to depend on a state's previous value and increment the previous value.
This video here does a great job explaining why |
||
|
|
||
| return ( | ||
| <div id="App"> | ||
| <header> | ||
| <h1>Application title</h1> | ||
| <h1>Chat between Vladimir and Estragon</h1> | ||
| <section id="heartWidget">{likedCount} ❤️s</section> | ||
| </header> | ||
| <main> | ||
| {/* Wave 01: Render one ChatEntry component | ||
| Wave 02: Render ChatLog component */} | ||
| <ChatLog | ||
| addLike={addLike} | ||
| removeLike={removeLike} | ||
| entries={chatMessages} | ||
| ></ChatLog> | ||
| </main> | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,44 @@ | ||
| import React from 'react'; | ||
| import { React, useState } from 'react'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import TimeStamp from './TimeStamp'; | ||
|
|
||
| const ChatEntry = ({ sender, body, timeStamp, liked, addLike, removeLike }) => { | ||
| const [like, setLike] = useState(liked); | ||
|
|
||
| const handleOnClick = () => { | ||
| if (like) { | ||
| removeLike(); | ||
| } else { | ||
| addLike(); | ||
| } | ||
|
|
||
| setLike(!like); | ||
| }; | ||
|
|
||
| const ChatEntry = (props) => { | ||
| 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 className="like" onClick={handleOnClick}> | ||
| {like ? '❤️' : '🤍'} | ||
| </button> | ||
| </section> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| ChatEntry.propTypes = { | ||
| //Fill with correct proptypes | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool, | ||
| addLike: PropTypes.func, | ||
| removeLike: PropTypes.func, | ||
|
Comment on lines
+39
to
+41
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. are these 3 required? |
||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import React from 'react'; | ||
| import './ChatLog.css'; | ||
| import PropTypes from 'prop-types'; | ||
| import ChatEntry from './ChatEntry'; | ||
|
|
||
| const ChatLog = ({ entries, addLike, removeLike }) => { | ||
| return ( | ||
| <section className="chat-log"> | ||
| {entries.map((message) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={message.id} | ||
| sender={message.sender} | ||
| body={message.body} | ||
| timeStamp={message.timeStamp} | ||
| liked={message.liked} | ||
| addLike={addLike} | ||
| removeLike={removeLike} | ||
| /> | ||
| ); | ||
| })} | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| entries: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool, | ||
| }) | ||
| ).isRequired, | ||
| addLike: PropTypes.func, | ||
| removeLike: PropTypes.func, | ||
|
Comment on lines
+35
to
+36
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. Are these two functions required? |
||
| }; | ||
|
|
||
| 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.
Remove unused, commented out code