-
Notifications
You must be signed in to change notification settings - Fork 153
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
Tigers Kindra Greenawalt #122
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"src" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,50 @@ | ||||||||||||
import React from 'react'; | ||||||||||||
import './App.css'; | ||||||||||||
import chatMessages from './data/messages.json'; | ||||||||||||
import ChatEntry from './components/ChatEntry'; | ||||||||||||
import ChatLog from './components/ChatLog'; | ||||||||||||
import './data/messages.json'; | ||||||||||||
import { useState } from 'react'; | ||||||||||||
|
||||||||||||
const App = () => { | ||||||||||||
const [entries, setEntries] = useState(chatMessages); | ||||||||||||
|
||||||||||||
const updateLikeCount = (id) => { | ||||||||||||
const newChatMessage = [...entries]; | ||||||||||||
for (let i = 0; i < newChatMessage.length; i++) { | ||||||||||||
const message = newChatMessage[i]; | ||||||||||||
if (ChatEntry.id === id) { | ||||||||||||
const newMessage = { ...message }; | ||||||||||||
if (newMessage.liked) { | ||||||||||||
newMessage.liked = false; | ||||||||||||
} else { | ||||||||||||
newMessage.liked = true; | ||||||||||||
} | ||||||||||||
newChatMessage[i] = newMessage; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
setEntries(newChatMessage); | ||||||||||||
}; | ||||||||||||
const likedTotal = (entries) => { | ||||||||||||
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. 👍 good job trying out |
||||||||||||
return entries.reduce((total, i) => { | ||||||||||||
return total + i.liked; | ||||||||||||
}, 0); | ||||||||||||
}; | ||||||||||||
|
||||||||||||
const totalLikeTally = likedTotal(entries); | ||||||||||||
|
||||||||||||
return ( | ||||||||||||
<div id="App"> | ||||||||||||
<header> | ||||||||||||
<h1>Application title</h1> | ||||||||||||
<h1>Application title ❤️ {totalLikeTally}</h1> | ||||||||||||
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. Wave 3 test isn't passing because it expects to find specific text: |
||||||||||||
</header> | ||||||||||||
<main> | ||||||||||||
{/* Wave 01: Render one ChatEntry component | ||||||||||||
Wave 02: Render ChatLog component */} | ||||||||||||
{/* // sender="Joe Biden" | ||||||||||||
// body="Get out by 8am. I'll count the silverware" | ||||||||||||
// timeStamp="2018-05-18T22:12:03Z" | ||||||||||||
// entries={entries} | ||||||||||||
// onUpdateLikeCount={updateLikeCount} */} | ||||||||||||
Comment on lines
+42
to
+46
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. Let's just remove this completely
Suggested change
|
||||||||||||
<ChatLog entries={entries} onUpdateLikeCount={updateLikeCount} /> | ||||||||||||
</main> | ||||||||||||
</div> | ||||||||||||
); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
import React from 'react'; | ||
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
|
||
const ChatEntry = (props) => { | ||
const like = props.liked ? '❤️' : '🤍'; | ||
const toggleLike = () => { | ||
props.onUpdateLikeCount(props.id); | ||
}; | ||
return ( | ||
<div className="chat-entry local"> | ||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<div className="chat-entry local" id={props.id}> | ||
<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={toggleLike}> | ||
{like} | ||
</button> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
id: PropTypes.number.isRequired, | ||
onUpdateLikeCount: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ChatEntry from './ChatEntry'; | ||
import './ChatLog.css'; | ||
|
||
const ChatLog = (props) => { | ||
return ( | ||
<ul className="chat-log"> | ||
{props.entries.map((message, i) => { | ||
return ( | ||
<ChatEntry | ||
sender={message.sender} | ||
body={message.body} | ||
timeStamp={message.timeStamp} | ||
key={i} | ||
liked={message.liked} | ||
id={message.id} | ||
onUpdateLikeCount={props.onUpdateLikeCount} | ||
/> | ||
); | ||
})} | ||
</ul> | ||
); | ||
}; | ||
|
||
ChatLog.prototype = { | ||
entries: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
id: PropTypes.number.isRequired, | ||
}) | ||
), | ||
onUpdateLikeCount: PropTypes.func.isRequired, | ||
}; | ||
|
||
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.
Is this supposed to be
ChatEntry
? This suggests it is a component. Did you meanmessage.id
?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.
Wave 3 isn't passing because no hearts are ever successfully updated because of the wrong variable.