diff --git a/src/App.css b/src/App.css
index d97beb4e..fdb1208c 100644
--- a/src/App.css
+++ b/src/App.css
@@ -13,6 +13,10 @@
align-items: center;
}
+header section p {
+ color: black;
+}
+
#App main {
padding-left: 2em;
padding-right: 2em;
diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684..c717ca31 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,33 @@
import './App.css';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
+import messagesData from './data/messages.json';
+
const App = () => {
+ const [messages, setMessages] = useState(messagesData);
+ const totalLikes = messages.filter(message => message.liked).length;
+
+ // Function to toggle like status of a message
+ const toggleLike = (id) => {
+ setMessages(messages.map(message => {
+ if (message.id === id) {
+ return { ...message, liked: !message.liked };
+ }
+ return message;
+ }));
+ };
+
return (
- Application title
+ Chat between Vladimir and Estragon
+
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index fe05efa0..8bbd7175 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,21 +1,38 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
+const ChatEntry = ({id, sender, body, timeStamp, liked, onToggleLike }) => {
+
+ const handleLikeClick = () => {
+ onToggleLike(id);
+ };
+
-const ChatEntry = () => {
return (
- // Replace the outer tag name with a semantic element that fits our use case
-
- Replace with name of sender
-
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
-
-
+
+ {sender}
+
+
{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 00000000..19c967f2
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,38 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+import './ChatLog.css';
+
+// ChatLog component to render a list of ChatEntry components
+const ChatLog = ({ entries, onToggleLike }) => {
+ return (
+
+ {entries.map((entry) => (
+
+ ))}
+
+ );
+};
+
+// Prop type validation for ChatLog component
+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;
\ No newline at end of file