diff --git a/src/App.js b/src/App.js
index c10859093..d70fddb77 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,32 @@
-import React from 'react';
+import React, {useState} from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';
+
const App = () => {
+ const [chatEntries, setChatEntries] = useState(chatMessages)
+
+ const likeCount = chatEntries.filter((entry) => entry.liked).length
+
+ const updateLike = (chatEntryId) => {
+ const updatedEntries = chatEntries.map((entry) => {
+ if (entry.id === chatEntryId) {
+ return { ...entry, liked: !entry.liked};
+ }
+ return entry;
+ })
+
+ setChatEntries(updatedEntries);
+ }
+
return (
- Application title
+ Chat 🪵 {likeCount} ❤️s
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css
index 05c3baa44..d0e8d6539 100644
--- a/src/components/ChatEntry.css
+++ b/src/components/ChatEntry.css
@@ -97,4 +97,5 @@ button {
.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
-}
\ No newline at end of file
+}
+
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..484910e46 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,34 @@
import React from 'react';
+// import TimeStamp from './TimeStamp';
import './ChatEntry.css';
import PropTypes from 'prop-types';
const ChatEntry = (props) => {
+ const heart = props.liked ? '❤️' : '🤍';
+
+ const handleLikeButton = () => {
+ props.updateLike(props.id);
+ };
+
return (
-
Replace with name of sender
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.body}
+ {props.timeStamp} years ago
+
);
};
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,
+ updateLike: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..ccb2ec33a
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,38 @@
+import React from 'react';
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+
+const ChatLog = (props) => {
+ return (
+
+ {props.entries.map((entry) => (
+
+ ))}
+
+ )
+}
+
+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,
+ // likeDecrease: PropTypes.func.isRequired,
+ updateLike: PropTypes.func.isRequired,
+}
+
+export default ChatLog;
\ No newline at end of file