diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684..798ee262 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,17 +1,50 @@
import './App.css';
+import messages from './data/messages.json';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
+
+const countTotalLikes = (chatData) =>{
+ return chatData.reduce((total, chat) => {
+ return total + (chat.liked ? 1 : 0);
+ }, 0);
+};
const App = () => {
+ const[chatData, setChatData] = useState(messages);
+ const totalLikes = countTotalLikes(chatData);
+
+ const handleToggleLike = id =>{
+ setChatData(chatData => {
+ return chatData.map(chat => {
+ if(chat.id === id) {
+ return ({ ...chat, liked: !chat.liked});
+ } else {
+ return chat;
+ }
+ });
+ });
+ };
+
return (
- Application title
+ Chat between Vladimir and Estragon
+ {totalLikes} ❤️s
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+ {
+ //
+ //
+ /* Wave 01: Render one ChatEntry component
+ messages*/
+ }
+
);
};
export default App;
+
diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css
index 05c3baa4..ece5ad73 100644
--- a/src/components/ChatEntry.css
+++ b/src/components/ChatEntry.css
@@ -97,4 +97,4 @@ button {
.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
-}
\ No newline at end of file
+}
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index fe05efa0..413463d0 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,21 +1,28 @@
import './ChatEntry.css';
+import TimeStamp from './TimeStamp.jsx';
+import PropTypes from 'prop-types';
-const ChatEntry = () => {
+const ChatEntry = ({ id, sender, body, timeStamp, liked, toggleLike }) => {
+ const heartColor = liked ? '❤️' : '🤍';
return (
- // Replace the outer tag name with a semantic element that fits our use case
-
- 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.isRequired,
+ toggleLike: PropTypes.func,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 00000000..6a17bf53
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,38 @@
+import ChatEntry from './ChatEntry.jsx';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, toggleLike }) => {
+ const chatComponents = entries.map(entry => {
+ return (
+
+ );
+ });
+ return (
+ <>
+ {chatComponents}
+ >
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
+ })).isRequired,
+ toggleLike: PropTypes.func,
+
+};
+
+export default ChatLog;
\ No newline at end of file