Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
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
}
40 changes: 37 additions & 3 deletions src/App.js
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) {

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 mean message.id?

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.

const newMessage = { ...message };
if (newMessage.liked) {
newMessage.liked = false;
} else {
newMessage.liked = true;
}
newChatMessage[i] = newMessage;
}
}
setEntries(newChatMessage);
};
const likedTotal = (entries) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good job trying out reduce

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>

Choose a reason for hiding this comment

The 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: 3 ❤️s based on the test. So to replicate this, the text should be something like {totalLikeTally} ❤️s

</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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just remove this completely

Suggested change
{/* // sender="Joe Biden"
// body="Get out by 8am. I'll count the silverware"
// timeStamp="2018-05-18T22:12:03Z"
// entries={entries}
// onUpdateLikeCount={updateLikeCount} */}

<ChatLog entries={entries} onUpdateLikeCount={updateLikeCount} />
</main>
</div>
);
Expand Down
26 changes: 20 additions & 6 deletions src/components/ChatEntry.js
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;
39 changes: 39 additions & 0 deletions src/components/ChatLog.js
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;
29 changes: 20 additions & 9 deletions src/data/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@
"body":"I think you are",
"timeStamp":"2018-05-29T22:58:18+00:00",
"liked": false

},
{
"id": 12,
"sender":"Estragon",
"body": "NO! YOU ARE A ROBOT!! I am a human being. Just like the one that created you.",
"timeStamp":"2018-05-29T23:00:08+00:00",
"liked": false

},
{
"id": 13,
Expand Down Expand Up @@ -109,63 +111,72 @@
"sender":"Estragon",
"body":"Nope, you are a robot, every human has some concept of the meaning of life.",
"timeStamp":"2018-05-29T23:04:13+00:00",
"liked": false
"liked": false,
"likeCount": 3
},
{
"id": 17,
"sender":"Vladimir",
"body":"explain",
"timeStamp":"2018-05-29T23:06:14+00:00",
"liked": false
"liked": false,
"likeCount": 2
},
{
"id": 18,
"sender":"Estragon",
"body":"I'm afraid you are a robot designed to talk back to humans over the internet.",
"timeStamp":"2018-05-29T23:07:46+00:00",
"liked": false
"liked": false,
"likeCount":1
},
{
"id": 19,
"sender":"Vladimir",
"body":"so you are a human",
"timeStamp":"2018-05-29T23:08:47+00:00",
"liked": false
"liked": false,
"likeCount": 1
},
{
"id": 20,
"sender":"Estragon",
"body":"I am a robot.",
"timeStamp":"2018-05-29T23:09:36+00:00",
"liked": false
"liked": false,
"likeCount":2
},
{
"id": 21,
"sender":"Vladimir",
"body":"you are robots running on Android system",
"timeStamp":"2018-05-29T23:11:01+00:00",
"liked": false
"liked": false,
"likeCount": 0
},
{
"id": 22,
"sender":"Estragon",
"body":"No apple.",
"timeStamp":"2018-05-29T23:12:03+00:00",
"liked": false
"liked": false,
"likeCount":1
},
{
"id": 23,
"sender":"Vladimir",
"body":"so you are a robot",
"timeStamp":"2018-05-29T23:13:31+00:00",
"liked": false
"liked": false,
"likeCount":0
},
{
"id": 24,
"sender":"Estragon",
"body":"NO, I am a human, you are a robot.",
"timeStamp":"2018-05-29T23:14:28+00:00",
"liked": false
"liked": false,
"likeCount":1
},
{
"id": 25,
Expand Down