diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..e053dbb5c 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,31 @@
import './App.css';
+import ChatLog from './components/ChatLog';
+import messagesData from './data/messages.json';
+import { useState } from 'react';
const App = () => {
+ const [entries, setEntries] = useState(messagesData);
+
+ const calcTotalLikes = () => {
+ return entries.filter(entry => entry.liked).length;
+ };
+
+ const toggleLike = (id) => {
+ setEntries(entries.map(entry =>
+ entry.id === id ? { ...entry, liked: !entry.liked } : entry
+ ));
+ };
+
+ const totalLikes = calcTotalLikes();
+
return (
-
Replace with name of sender
+
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
);
};
ChatEntry.propTypes = {
- // Fill with correct proptypes
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
+ onLike: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..5c6607e0e
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,27 @@
+import './ChatLog.css';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, onLike }) => {
+ return (
+
+ {entries.map((entry) => (
+ onLike(entry.id)}
+ />
+ ))}
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.array.isRequired,
+ onLike: PropTypes.func.isRequired,
+};
+
+export default ChatLog;
\ No newline at end of file