-
Notifications
You must be signed in to change notification settings - Fork 111
sharks- jeannie #105
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?
sharks- jeannie #105
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,40 @@ | ||
| import React from 'react'; | ||
| import { React, useState } from 'react'; | ||
| import './App.css'; | ||
| import ChatEntry from './components/ChatEntry'; | ||
| import chatMessages from './data/messages.json'; | ||
|
|
||
| import ChatLog from './components/ChatLog' | ||
| const App = () => { | ||
|
|
||
| const [messageData, setMessageData] = useState(chatMessages) | ||
| const [likeData, setLikeData] = useState(0) | ||
|
|
||
| const updateMessage = (messageToUpdate) => { | ||
| const entries = messageData.map((message) => { | ||
| if (message.id === messageToUpdate.id) { | ||
| return messageToUpdate | ||
| } | ||
|
Comment on lines
+12
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. hmm I'm a little confused by this if statement and variable. I don't see you using I think all you need is lines 16-22 |
||
| else if (messageToUpdate) { | ||
| setLikeData(likeData + 1); | ||
|
|
||
| } else { | ||
| setLikeData(likeData - 1); | ||
| }; | ||
| }) | ||
| }; | ||
|
|
||
| return ( | ||
| <div id="App"> | ||
| <header> | ||
| <h1>Application title</h1> | ||
| <h1>Chat Log</h1> | ||
| <h2>Like count {likeData} ❤️s</h2> | ||
| </header> | ||
| <main> | ||
| {/* Wave 01: Render one ChatEntry component | ||
| { | ||
| <ChatLog entries={chatMessages} | ||
| onUpdateMessage={updateMessage}> | ||
| </ChatLog> | ||
|
|
||
| /* Wave 01: Render one ChatEntry component | ||
| Wave 02: Render ChatLog component */} | ||
| </main> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,22 +1,53 @@ | ||||||||||||
| 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, liked, timeStamp, id, onUpdateMessage }) => { | ||||||||||||
|
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. 👍 |
||||||||||||
| const [isLiked, setIsLiked] = useState(liked); | ||||||||||||
|
|
||||||||||||
| if (isLiked) { | ||||||||||||
| console.log('is liked'); | ||||||||||||
| } else { | ||||||||||||
| console.log('is unliked'); | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+9
to
+13
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. Don't forget to get rid of debugging comments once you're ready to submit the final submission
Suggested change
|
||||||||||||
|
|
||||||||||||
| const updateLiked = () => { | ||||||||||||
| console.log('updating heart') | ||||||||||||
|
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.
Suggested change
|
||||||||||||
| setIsLiked(!isLiked); | ||||||||||||
| onUpdateMessage({ | ||||||||||||
| sender: sender, | ||||||||||||
| body: body, | ||||||||||||
| timeStamp: timeStamp, | ||||||||||||
| id: id, | ||||||||||||
|
Comment on lines
+19
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. hmm you are giving this function a lot of editing power when it only needs to update the |
||||||||||||
| isLiked: !isLiked, | ||||||||||||
| }) | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| const heartColor = isLiked ? '❤️' : '🤍'; | ||||||||||||
|
|
||||||||||||
| 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 onClick={updateLiked} className="like">{heartColor}</button> | ||||||||||||
| </section> | ||||||||||||
| </div> | ||||||||||||
| ); | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| ChatEntry.propTypes = { | ||||||||||||
| //Fill with correct proptypes | ||||||||||||
| sender: PropTypes.string.isRequired, | ||||||||||||
| body: PropTypes.string.isRequired, | ||||||||||||
| timeStamp: PropTypes.string.isRequired, | ||||||||||||
| id: PropTypes.number.isRequired, | ||||||||||||
| isLiked: PropTypes.bool.isRequired, | ||||||||||||
| onUpdateMessage: PropTypes.func.isRequired | ||||||||||||
|
|
||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| export default ChatEntry; | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import ChatEntry from './ChatEntry'; | ||
| import './ChatLog.css'; | ||
|
|
||
| const ChatLog = ({ entries, id, liked, onUpdateMessage }) => { | ||
|
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 ( | ||
| <ul> | ||
| {entries.map(chat => { | ||
| return ( | ||
| <ChatEntry | ||
| sender={chat.sender} | ||
| body={chat.body} | ||
| timeStamp={chat.timeStamp} | ||
| id={chat.id} | ||
| isLiked={chat.liked} | ||
| onUpdateMessage={onUpdateMessage} | ||
| /> | ||
| ); | ||
| })} | ||
| </ul> | ||
| ); | ||
| }; | ||
|
|
||
| ChatLog.propTypes = { | ||
| entries: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| sender: PropTypes.string, | ||
| body: PropTypes.string, | ||
| timeStamp: PropTypes.string, | ||
| id: PropTypes.number.isRequired, | ||
| liked: PropTypes.bool.isRequired, | ||
| onUpdateMessage: PropTypes.func.isRequire | ||
|
|
||
| }) | ||
| ) | ||
| } | ||
|
|
||
| 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.
👍