diff --git a/src/App.js b/src/App.js
index c10859093..5711460b3 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,39 @@
import React from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
+
const App = () => {
+ const [entries, setEntries] = useState(chatMessages);
+ let [likeCount, setLikes] = useState(0);
+
+ const changeHeartColor = (id) => {
+ const newEntries = entries.map((entry) => ({...entry}));
+ for (const entry of newEntries) {
+ if (entry.id === id) {
+ entry.liked = !entry.liked;
+ if (entry.liked) {
+ likeCount += 1;
+ }
+ }
+ }
+ setEntries(newEntries);
+ setLikes(likeCount);
+ };
+
return (
- Application title
+ Chat Log
+ {likeCount} ❤️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..bd9b0c18e 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 heartToggle = () => {
+ props.heartCallback(props.id);
+ };
+
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,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..403bdd2df
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,34 @@
+import React from 'react';
+import './ChatLog.css';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+
+const ChatLog = (props) => {
+ const chatComponents = props.entries.map((entry) => {
+ return (
+
+
+
+ );
+ });
+ return (
+
+ {chatComponents}
+
+ )
+}
+
+ChatLog.propTypes = {
+ entries: PropTypes.array.isRequired,
+};
+
+export default ChatLog;
+
diff --git a/src/components/ChatLog.test.js b/src/components/ChatLog.test.js
index 96f89ebc3..3c19b4e5a 100644
--- a/src/components/ChatLog.test.js
+++ b/src/components/ChatLog.test.js
@@ -5,26 +5,31 @@ import { render, screen } from "@testing-library/react";
const LOG = [
{
+ id: 0,
sender: "Vladimir",
body: "why are you arguing with me",
timeStamp: "2018-05-29T22:49:06+00:00",
},
{
+ id: 1,
sender: "Estragon",
body: "Because you are wrong.",
timeStamp: "2018-05-29T22:49:33+00:00",
},
{
+ id: 2,
sender: "Vladimir",
body: "because I am what",
timeStamp: "2018-05-29T22:50:22+00:00",
},
{
+ id: 3,
sender: "Estragon",
body: "A robot.",
timeStamp: "2018-05-29T22:52:21+00:00",
},
{
+ id: 4,
sender: "Vladimir",
body: "Notabot",
timeStamp: "2019-07-23T22:52:21+00:00",