diff --git a/src/App.js b/src/App.js
index c10859093..2e5cf0254 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,38 @@
-import React from 'react';
+import React, {useState} from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatEntry from './components/ChatEntry';
+import ChatLog from './components/ChatLog';
const App = () => {
+ const [messages, setMessages] = useState(chatMessages)
+
+ const handleLike = id => {
+ setMessages(prevMessages => {
+ return prevMessages.map(message => {
+ if (id === message.id) {
+ return {
+ ...message,
+ liked: !message.liked
+ };
+ }
+ return message;
+ })
+ })
+ }
+
+ const totalLikes = messages.filter(entry => entry.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.js b/src/components/ChatEntry.js
index b92f0b7b2..d03f88024 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,30 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
+ const heartFill = props.liked ? '❤️' : '🤍';
+
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,
+ handleLike: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..a756df6e3
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,40 @@
+import React from 'react';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+
+const ChatLog = (props) => {
+ const chatEntries = props.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,
+ })),
+ handleLike: PropTypes.func.isRequired,
+};
+
+export default ChatLog;
\ No newline at end of file