diff --git a/src/App.js b/src/App.js
index c1085909..d2ac9ac4 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,39 @@
-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 = () => {
+ console.log(chatMessages);
+ const [chatsMessages, setChatState] = useState(chatMessages);
+ const changeLike = (id) => {
+ const newData = chatsMessages.map((chat) => {
+ if (chat.id === id) {
+ chat.liked = !chat.liked;
+ return chat;
+ }
+ return chat;
+ });
+ return setChatState(newData);
+ };
+ const sumLikes = () => {
+ const likedTrue = chatsMessages.filter((chat) => {
+ return chat.liked === true;
+ });
+ return likedTrue.length;
+ };
+
return (
- Application title
+ Chats
+ {sumLikes()} ❤️'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 b92f0b7b..5294137e 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,15 +1,34 @@
-import React from 'react';
+import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
+ const [liked, setLike] = useState(false);
+ const changeHeart = !liked ? '🤍' : '❤️';
+ const changeLike = (id) => {
+ const likeState = setLike(!liked);
+ props.onChangeLike(id);
+
+ return likeState;
+ };
+
return (
-
Replace with name of sender
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.body}
+
+ years ago
+
+
);
@@ -17,6 +36,12 @@ const ChatEntry = (props) => {
ChatEntry.propTypes = {
//Fill with correct proptypes
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ id: PropTypes.number.isRequired,
+ liked: PropTypes.bool.isRequired,
+ onChangeLike: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 00000000..0e8a96ef
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,27 @@
+import { React } from 'react';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = (props) => {
+ const chatMessageArray = props.chatsMessages.map((chat) => {
+ return (
+
+ );
+ });
+ return chatMessageArray;
+};
+
+ChatLog.propTypes = {
+ chatsMessages: PropTypes.arrayOf(PropTypes.object).isRequired,
+ onChangeLike: PropTypes.func.isRequired,
+};
+
+export default ChatLog;