diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..a5b5f1f37 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,17 +1,40 @@
+import { useState } from 'react';
import './App.css';
+import messages from './data/messages.json';
+import ChatLog from './components/ChatLog';
const App = () => {
+ const [chatMessages, setChatMessages] = useState(messages);
+
+ const handleLikeToggle = (id) => {
+ setChatMessages((prevMessages) =>
+ prevMessages.map((message) =>
+ message.id === id
+ ? { ...message, liked: !message.liked }
+ : message
+ )
+ );
+ };
+
+ const totalLikes = chatMessages.filter((message) => message.liked).length;
+ const person1 = messages[0].sender;
+ const person2 = messages[1].sender;
+
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.isRequired,
+ onToggleLike: PropTypes.func.isRequired,
};
export default ChatEntry;
+
+
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..25e97d0e2
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,40 @@
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry.jsx';
+import './ChatLog.css';
+
+const ChatLog = ({ entries, onToggleLike }) => {
+ const chatEntryComponents = entries.map((entry) => {
+ return (
+
+ );
+ });
+
+ return (
+
+ {chatEntryComponents}
+
+ );
+};
+
+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,
+ onToggleLike: PropTypes.func.isRequired,
+};
+
+export default ChatLog;