diff --git a/README.md b/README.md
index 71851feea..caac25c4c 100644
--- a/README.md
+++ b/README.md
@@ -33,4 +33,3 @@ Follow your curiosity to learn more about front-end testing:
- [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/)
-
diff --git a/project-docs/wave-01.md b/project-docs/wave-01.md
index 8444d2c5a..19b13e687 100644
--- a/project-docs/wave-01.md
+++ b/project-docs/wave-01.md
@@ -21,3 +21,4 @@ Usually our convention for styles in React applications is to have a separate CS
## Tests
This component has a set of tests that ensure that props passed to the component appear in the browser. To pass the tests, the component must be named `ChatEntry` with props `sender`, `body`, and `timeStamp`.
+
diff --git a/src/App.js b/src/App.js
index c10859093..20bab6949 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,19 +1,39 @@
import React from 'react';
import './App.css';
+import { useState } from 'react';
import chatMessages from './data/messages.json';
+import ChatLog from './components/Chatlog';
const App = () => {
+ const [chatJson, setchatJson] = useState(chatMessages);
+
+ const updatechatJson = (id) => {
+ const updatedChat = chatJson.map((chat) => {
+ if (chat.id === id) {
+ return { ...chat, liked: !chat.liked };
+ } else {
+ return chat;
+ }
+ });
+ setchatJson(updatedChat);
+ };
+
+ const Hearts = () => {
+ return chatJson.reduce((total, message) => {
+ return message.liked ? total + 1 : total;
+ }, 0);
+ };
+
return (
- Application title
+ Human & Robot
+ LikeCount: {Hearts()} ❤️
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
};
-
export default App;
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..d3a68d75d 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -2,21 +2,36 @@ import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+const filledHeart = '❤️';
+const emptyHeart = '🤍';
+
const ChatEntry = (props) => {
+ const heartOrNot = props.liked ? filledHeart : emptyHeart;
+ const className = props.sender === 'Estragon' ? 'remote' : 'local';
+
+ const handleClick = (id) => {
+ props.handleLike(id);
+ };
return (
-
-
Replace with name of sender
+
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.body}
+ {props.timeStamp}
+
);
};
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,
};
export default ChatEntry;
diff --git a/src/components/Chatlog.js b/src/components/Chatlog.js
new file mode 100644
index 000000000..3573f4dd6
--- /dev/null
+++ b/src/components/Chatlog.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+
+const ChatLog = (props) => {
+ const jsonMessages = props.entries.map((messages) => {
+ return (
+
+ );
+ });
+ return
{jsonMessages}
;
+};
+
+ChatEntry.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,
+ key: PropTypes.number.isRequired,
+ })
+ ),
+};
+
+export default ChatLog;
diff --git a/src/components/TimeStamp.js b/src/components/TimeStamp.js
index 51232778b..e9368fdbe 100644
--- a/src/components/TimeStamp.js
+++ b/src/components/TimeStamp.js
@@ -1,6 +1,8 @@
+import React from 'react';
import { DateTime } from 'luxon';
+import PropTypes from 'prop-types';
-const TimeStamp = (props) => {
+const timeStamp = (props) => {
const time = DateTime.fromISO(props.time);
const absolute = time.toFormat('MMMM Do YYYY, h:mm:ss a');
const relative = time.toRelative();
@@ -8,4 +10,11 @@ const TimeStamp = (props) => {
return
{relative};
};
-export default TimeStamp;
+timeStamp.propTypes = {
+ timeStampmessage: PropTypes.arrayOf(
+ PropTypes.shape({
+ messageContent: PropTypes.number,
+ })
+ ),
+};
+export default timeStamp;