diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..598e8249c 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,28 @@
import './App.css';
+import ChatLog from './components/ChatLog';
+import message from './data/messages.json';
+import {useState} from 'react';
const App = () => {
+ const [chatData, setChatData] = useState(message);
+ const togglelikes = (id) => {
+ setChatData( chatData => chatData.map(chat => {
+ if (chat.id === id){
+ return {...chat, liked: !chat.liked};
+ }else {
+ return chat;
+ }
+ }));
+ };
+ const totalLikes = chatData.filter((chat) => chat.liked).length;
return (
- Application title
+ Chat Log
+ {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..c34aeb64f 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,20 +1,30 @@
import './ChatEntry.css';
+import TimeStamp from './TimeStamp';
+import PropTypes from 'prop-types';
-const ChatEntry = () => {
+const ChatEntry = ({id,sender,body,timeStamp,liked,chatClicked}) => {
+ const heartColor = liked ? '❤️' : '🤍';
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.string.isRequired,
+ chatClicked: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..babae8605
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,37 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+import './ChatLog.css';
+
+const ChatLog = ({entries, chatClicked}) => {
+ const chatComponents = entries.map((chat) => {
+ return (
+
+
+
+ );
+ });
+ return (
+ <>
+ {chatComponents}
+ >
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ })).isRequired,
+ chatClicked: PropTypes.func.isRequired,
+};
+
+export default ChatLog;
\ No newline at end of file