diff --git a/package.json b/package.json
index 5bbba246d..a651f1486 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"luxon": "^2.4.0",
+ "moment": "^2.29.4",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "5.0.0"
diff --git a/src/App.js b/src/App.js
index c10859093..11ad301ad 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,22 @@
-import React from 'react';
+import React, { useState } from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatLog from './components/ChatLog';
const App = () => {
+ const [likesCount, setLikesCount] = useState(0);
+
+ const updateLikesCount = (liked) => {
+ setLikesCount(likesCount + (liked ? 1 : -1));
+ };
+
return (
- Application title
+ {likesCount} ❤️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..be5cc2e47 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,15 +1,24 @@
-import React from 'react';
+import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import moment from 'moment';
const ChatEntry = (props) => {
+ const [liked, setLiked] = useState(false);
+
+ const toggleLike = () => {
+ setLiked(!liked);
+ props.onClickLike(!liked);
+ };
+
return (
-
Replace with name of sender
+
{ props.sender }
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ { props.body }
+ { moment(props.timeStamp).fromNow() }
+
);
@@ -17,6 +26,12 @@ const ChatEntry = (props) => {
ChatEntry.propTypes = {
//Fill with correct proptypes
+ id: PropTypes.number,
+ sender: PropTypes.string,
+ body: PropTypes.string,
+ timeStamp: PropTypes.string,
+ liked: PropTypes.bool,
+ onClickLike: PropTypes.func,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..556090e05
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,21 @@
+import React from 'react';
+// import './ChatLog.css';
+import ChatEntry from './ChatEntry';
+
+const ChatLog = (props) => {
+ const chatComponents = props.entries.map((entry) => {
+ return (
+
+ );
+ });
+
+ return chatComponents;
+};
+
+export default ChatLog;
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 092a12c75..842964dab 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7107,6 +7107,11 @@ mkdirp@~0.5.1:
dependencies:
minimist "^1.2.6"
+moment@^2.29.4:
+ version "2.29.4"
+ resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
+ integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
+
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"