diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7a230e1c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.testing.pytestArgs": [ + "src" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index c1085909..1870d42b 100644 --- a/src/App.js +++ b/src/App.js @@ -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) => { + return entries.reduce((total, i) => { + return total + i.liked; + }, 0); + }; + + const totalLikeTally = likedTotal(entries); + return (
-

Application title

+

Application title ❤️ {totalLikeTally}

- {/* 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} */} +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b..32022c35 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -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 ( -
-

Replace with name of sender

+
+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+ +

+
); }; 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; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..7bc1faab --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,39 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; +import './ChatLog.css'; + +const ChatLog = (props) => { + return ( + + ); +}; + +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; diff --git a/src/data/messages.json b/src/data/messages.json index 64fdb053..fe8cf899 100644 --- a/src/data/messages.json +++ b/src/data/messages.json @@ -75,6 +75,7 @@ "body":"I think you are", "timeStamp":"2018-05-29T22:58:18+00:00", "liked": false + }, { "id": 12, @@ -82,6 +83,7 @@ "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, @@ -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,