-
Notifications
You must be signed in to change notification settings - Fork 35
Crow -Sophie #35
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?
Crow -Sophie #35
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,14 +1,26 @@ | ||
| import './App.css'; | ||
| import { useState } from 'react'; | ||
| import messages from './data/messages.json'; | ||
| import ChatLog from './components/ChatLog'; | ||
|
|
||
|
|
||
| const App = () => { | ||
| const [entries, setEntries] = useState(messages); | ||
|
|
||
| const toggleLiked = (id) => { | ||
| setEntries((prev) => prev.map((m) => (m.id === id ? { ...m, liked: !m.liked } : m))); | ||
| }; | ||
|
Comment on lines
+10
to
+12
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. The only piece of feedback I have here is that your naming for the message object, |
||
|
|
||
| const likeCount = entries.filter((m) => m.liked).length; | ||
|
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'll see that there are a number of ways to implement this logic. Though this is functionally sound, I will say that if I see the Find more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce |
||
|
|
||
| return ( | ||
| <div id="App"> | ||
| <header> | ||
| <h1>Application title</h1> | ||
| <div className="likes-count">{likeCount} ❤️s</div> | ||
|
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. ✅ |
||
| </header> | ||
| <main> | ||
| {/* Wave 01: Render one ChatEntry component | ||
| Wave 02: Render ChatLog component */} | ||
| <ChatLog entries={entries} onToggleLiked={toggleLiked} /> | ||
|
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. ✅ |
||
| </main> | ||
| </div> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,21 +1,34 @@ | ||||||
| import './ChatEntry.css'; | ||||||
| import PropTypes from 'prop-types'; | ||||||
| import TimeStamp from './TimeStamp'; | ||||||
|
|
||||||
| const ChatEntry = () => { | ||||||
| const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLiked }) => { | ||||||
|
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. Excellent formatting. |
||||||
| return ( | ||||||
| // Replace the outer tag name with a semantic element that fits our use case | ||||||
| <replace-with-relevant-semantic-element className="chat-entry local"> | ||||||
| <h2 className="entry-name">Replace with name of sender</h2> | ||||||
| <article className="chat-entry local"> | ||||||
| <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={() => onToggleLiked && onToggleLiked(id)} | ||||||
|
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. @SophieQA, not sure why you have
Suggested change
|
||||||
| > | ||||||
| {liked ? '❤️' : '🤍'} | ||||||
| </button> | ||||||
| </section> | ||||||
| </replace-with-relevant-semantic-element> | ||||||
| </article> | ||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| 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, | ||||||
| onToggleLiked: PropTypes.func, | ||||||
|
Comment on lines
+26
to
+31
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. Great work on these proptypes, remember that they have been sunsetted in React and that will be using other type checking frameworks like Typescript. |
||||||
| }; | ||||||
|
|
||||||
| export default ChatEntry; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import ChatEntry from './ChatEntry'; | ||
| import './ChatLog.css'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ChatLog = ({ entries, onToggleLiked }) => { | ||
| const chatEntries = entries.map((message) => { | ||
| return ( | ||
| <ChatEntry | ||
| key={message.id} | ||
| id={message.id} | ||
| sender={message.sender} | ||
| body={message.body} | ||
| timeStamp={message.timeStamp} | ||
| liked={message.liked} | ||
| onToggleLiked={onToggleLiked} | ||
|
Comment on lines
+9
to
+15
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. ✅ |
||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| return ( | ||
| <section className="chat-log"> | ||
| {chatEntries} | ||
|
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. ✅ |
||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| entries: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| id: PropTypes.number.isRequired, | ||
| sender: PropTypes.string.isRequired, | ||
| body: PropTypes.string.isRequired, | ||
| timeStamp: PropTypes.string.isRequired, | ||
| liked: PropTypes.bool.isRequired, | ||
| }) | ||
| ).isRequired, | ||
| onToggleLiked: PropTypes.func.isRequired, | ||
| }; | ||
|
Comment on lines
+27
to
+38
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. ✅ |
||
|
|
||
| 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.
✅