diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684..d4aa5888 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,17 +1,47 @@
import './App.css';
+import messagesData from './data/messages.json';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
const App = () => {
+ const [chatData, setChatData] = useState(messagesData);
+ const [likedCount, setLikedCount] = useState(0);
+ const toggleLike = (chatEntryId) => {
+ setChatData((prevChatData) => {
+ const updatedChatData = prevChatData.map((chatEntry) => {
+ if (chatEntry.id === chatEntryId) {
+ return { ...chatEntry, liked: !chatEntry.liked };
+ } else {
+ return chatEntry;
+ }
+ });
+ let totalLikes = 0;
+ updatedChatData.forEach((chatEntry) => {
+ if (chatEntry.liked) {
+ totalLikes++;
+ }
+ });
+ setLikedCount(totalLikes);
+ return updatedChatData;
+ });
+ };
+
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,
+ onLikeToggle: PropTypes.func.isRequired,
};
-export default ChatEntry;
+export default ChatEntry;
\ No newline at end of file
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 00000000..18bbe522
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,40 @@
+import './ChatLog.css';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, onLikeToggle }) => {
+ const chatEntryComponents = entries.map((chatEntry) => {
+ 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,
+ onLikeToggle: PropTypes.func.isRequired,
+};
+
+export default ChatLog;
\ No newline at end of file