diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..ea60bb7c1 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,37 @@
import './App.css';
+import ChatLog from './components/ChatLog';
+import messages from './data/messages.json';
+import { useState } from 'react';
const App = () => {
+ const [messageLogs, setMessageLogs] = useState(messages);
+
+ // handles what happens when 'like' button is clicked:
+ const toggleLike = (id) => {
+ const update = messageLogs.map((message) => {
+ if (message.id === id) {
+ return {...message, liked: !message.liked};
+ } else {
+ return message;
+ }
+ });
+
+ setMessageLogs(update);
+ };
+
+ // helper f(x) to easily retrieve/display like count:
+ const getLikeCount = () => {
+ return messageLogs.filter((message) => message.liked).length;
+ };
+
return (
- Application title
+ Messages
+ {getLikeCount()} ❤️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..63597571e 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,20 +1,27 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
-const ChatEntry = () => {
+const ChatEntry = (props) => {
return (
-
Replace with name of sender
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.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,
+ onLikeClick: PropTypes.func.isRequired
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..f04d92dd2
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,33 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = (props) => {
+ return (
+
+ {props.entries.map((message) => (
+
+ ))}
+
);
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ })
+ ).isRequired,
+ onLikeClick: PropTypes.func.isRequired,
+};
+
+export default ChatLog;