diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..435772bf6 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,47 @@
import './App.css';
+import DATA from './data/messages.json';
+// import ChatEntry from './components/ChatEntry';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
+import './App.css';
+
+
const App = () => {
+ const [messagesData, setMessagesData] = useState(DATA);
+ const toggleLike = (Id) => {
+ const updatedMessages = messagesData.map((msg) => {
+ if (msg.id === Id) {
+ return { ...msg, liked: !msg.liked };
+ } else {
+ return msg;
+ }
+ });
+ setMessagesData(updatedMessages);
+ };
+ const likedMessages = messagesData.filter((message) => {
+ return message.liked === true;
+ });
+ const totalLikes = likedMessages.length;
return (
- Application title
+ Chat Between Vladimer and Estragon
+
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
+ {
+ /* 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..61cae5a90 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,20 +1,31 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
-const ChatEntry = () => {
+const ChatEntry = ({ id, sender, body, timeStamp, liked, onLikeToggle}) => {
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;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..86e69feee
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,39 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+import './ChatLog.css';
+
+const ChatLog = ({entries, onLikeToggle }) =>{
+ 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,
+ onLikeToggle: PropTypes.func.isRequired,
+};
+
+export default ChatLog
\ No newline at end of file