diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 000000000..6f3a2913e
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "liveServer.settings.port": 5501
+}
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index c10859093..7946d03d1 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,40 @@
import React from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';
+import { useState } from 'react';
const App = () => {
+ const [chatData, setChatData] = useState(chatMessages);
+
+ const toggleLikeButton = (id) => {
+ setChatData((chatData) =>
+ chatData.map((chat) => {
+ if (chat.id === id) {
+ return { ...chat, liked: !chat.liked };
+ } else {
+ return chat;
+ }
+ })
+ );
+ };
+
+ const calcTotalLikes = (chatData) => {
+ return chatData.reduce((total, current) => {
+ return total + current.liked;
+ }, 0);
+ };
+
+ const displayTotalLiked = calcTotalLikes(chatData);
+
return (
Application title
+ {displayTotalLiked} ❤️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..bfe9c563a 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,32 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
+ const heartIcon = props.liked ? '❤️' : '🤍';
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
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..4794689e3
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+
+const ChatLog = (props) => {
+ return (
+
+ {props.entries.map((entry) => (
+
+ ))}
+
+ );
+};
+
+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,
+ })
+ ),
+ onToggleLiked: PropTypes.func.isRequired,
+};
+
+export default ChatLog;