diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..65d939f9d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "*test.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index c10859093..bd6a7f6b2 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,43 @@ import React from 'react'; import './App.css'; -import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import { useState } from 'react'; +import Chats from './data/messages.json'; + const App = () => { + const [chatMessages, setChatMessages] = useState(Chats); + + const heartClick = (entryToUpdate) => { + const entries = chatMessages.map((message) => { + if (message.id === entryToUpdate.id){ + return entryToUpdate; + } + return message; + }); + setChatMessages(entries); + }; + + const countLikes = (chatMessages) => { + let likeCount = 0; + for(const message of chatMessages){ + if (message.liked=== true){ + likeCount++; + } + }; + return likeCount; + }; + const heartTotal = countLikes(chatMessages); return (

Application title

+

Total Likes: {heartTotal} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
+
); }; diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..7b1e88832 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,38 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; + + +const ChatEntry = ({id, sender, body, timeStamp, liked, heartClick}) => { + + const clickLikedHeart = () => { + heartClick( + {id:id, + sender:sender, + body:body, + timeStamp:timeStamp, + liked:!liked})}; -const ChatEntry = (props) => { return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{body}

+

+
); }; 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, + heartClick: PropTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..aa51333df --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,31 @@ +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + + + +const ChatLog = ({entries, heartClick}) => { + + const getChatLog = () => { + return entries.map((entry) => { + return ( + + ); + }); + }; + return ( +
+ {getChatLog(entries)} +
+ ) +}; + +export default ChatLog; \ No newline at end of file diff --git a/src/data/messages.json b/src/data/messages.json index 64fdb053c..16f395f63 100644 --- a/src/data/messages.json +++ b/src/data/messages.json @@ -1,3 +1,4 @@ + [ { "id": 1,