diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..23ea72958 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,32 @@
import './App.css';
+import ChatEntry from './components/ChatEntry';
+import messages from './data/messages.json';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
const App = () => {
+ const [chatMessages, setChatMessages] = useState(messages);
+
+ const toggleLike = (id) => {
+ setChatMessages(chatMessages => chatMessages.map(message => {
+ if (message.id === id) {
+ return { ...message, liked: !message.liked };
+ } else {
+ return message;
+ }
+ }));
+ };
+
+ const totalLikes = chatMessages.filter(message => message.liked).length;
+
return (
Application title
+ {totalLikes} 🤍s
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index 15c56f96b..7f4b854a2 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,20 +1,35 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
+const ChatEntry = ({sender, body, timeStamp, id, liked, onToggleLike}) => {
+ const handleClick = () => {
+ onToggleLike(id);
+ };
-const ChatEntry = () => {
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..ed5c3f9d5
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,38 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, onToggleLike }) => {
+ const chatEntries = entries.map((entry) => {
+ return(
+
+ );
+ });
+ return (
+ <>
+ {chatEntries}
+ >
+ );
+};
+
+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;