diff --git a/src/App.js b/src/App.js
index c10859093..52ba38022 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,36 @@
-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 = () => {
+ //Brains
+ const [updateChatLog, setUpdateChatLog] = useState(chatMessages);
+ // for every item in updated ChatLog replace existing message with latest message.
+ const refreshMessageLog = (updatedEntry) => {
+ const newChatData = updateChatLog.map((entry) => {
+ if (entry.id === updatedEntry.id) {
+ return updatedEntry;
+ } else {
+ return entry;
+ }
+ });
+ setUpdateChatLog(newChatData);
+ };
+
+ const likeCount = updateChatLog.reduce((total, entry) => {
+ return total + entry.liked;
+ }, 0);
+
+ //Beauty
return (
- Application title
+ Hope's React Practice 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..c6a470ab2 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,15 +1,36 @@
import React from 'react';
import './ChatEntry.css';
+import TimeStamp from './TimeStamp';
import PropTypes from 'prop-types';
-const ChatEntry = (props) => {
+const ChatEntry = ({ id, sender, body, timeStamp, liked, onUpdate }) => {
+ //Brains
+ const handleChangeHeart = () => {
+ const updatedEntry = {
+ id: id,
+ sender: sender,
+ body: body,
+ timeStamp: timeStamp,
+ liked: !liked,
+ };
+ onUpdate(updatedEntry);
+ };
+
+ //Beauty
+ const renderHeart = () => {
+ return liked ? '❤️' : '🤍';
+ };
return (
-
Replace with name of sender
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
+
+
);
@@ -17,6 +38,11 @@ const ChatEntry = (props) => {
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..ed2b6d740
--- /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 = ({ entries, update }) => {
+ return entries.map((entry) => {
+ //Mapping each entry of chatMessages array to a chatEntry react component
+ return (
+
+ );
+ });
+};
+
+ChatLog.propTypes = {
+ //Fill with correct proptypes
+ entries: PropTypes.arrayOf(PropTypes.object).isRequired,
+ update: PropTypes.func.isRequired,
+};
+export default ChatLog;