diff --git a/src/App.css b/src/App.css
index d97beb4e..bcca8565 100644
--- a/src/App.css
+++ b/src/App.css
@@ -28,6 +28,7 @@
#App header section {
background-color: #e0ffff;
+ padding: 0.2em;
}
#App .widget {
@@ -71,4 +72,9 @@
.purple {
color: purple
-}
\ No newline at end of file
+}
+
+h2 {
+ color: black;
+
+}
diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684..cad1d309 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,75 @@
import './App.css';
+import {useState} from 'react';
+import messagesJSON from './data/messages.json';
+import ChatLog from './components/ChatLog';
+
+
+const countTotalLikes = (messageData) => {
+ return messageData.reduce((acc, entry) => acc + entry.liked, 0);
+ //explain what reduce is doing here
+ //
+};
+
+const toggleLike = (messageId) => {
+ return {
+ ...messageId,
+ liked: !messageId.liked,
+ };
+};
const App = () => {
+
+ const [messageData, setMessagesData] = useState(messagesJSON);
+
+ const likeMessage = (messageId) => {
+ setMessagesData((prevMessagesData) => {
+ return prevMessagesData.map((entry) => {
+ if (entry.id === messageId) {
+ return toggleLike(entry);
+ } else {
+ return entry;
+ }
+ });
+ });
+ };
+
+ const likeCount = countTotalLikes(messageData);
+
+ const findSenderNames = (messageData) => {
+ const senderNames = messageData.map((entry) => {
+ return entry.sender;
+ });
+ return new Set(senderNames);
+ };
+
+ const setHeaderTitle = (messageData) => {
+ const senderNames = Array.from(findSenderNames(messageData));
+ return senderNames.reduce((acc, name, index) => {
+ if (index === senderNames.length - 1 && index !== 0) {
+ return `${acc} and ${name}`;
+ } else if (index === 0) {
+ return name;
+ } else {
+ return `${acc}, ${name}`;
+ }
+ }, '');
+ };
+
return (
- Application title
+ {setHeaderTitle(messageData)}
+
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
+
);
diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css
index 05c3baa4..acb703bf 100644
--- a/src/components/ChatEntry.css
+++ b/src/components/ChatEntry.css
@@ -97,4 +97,9 @@ button {
.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
-}
\ No newline at end of file
+}
+
+
+
+
+
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index fe05efa0..9f31ff8e 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,21 +1,34 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
+const ChatEntry = ({ id, sender, body, timeStamp, liked, onLike }) => {
+
+ const handleLike = () => {
+ onLike(id);
+ };
+
+ const like = liked ? '❤️' : '🤍';
-const ChatEntry = () => {
return (
- // Replace the outer tag name with a semantic element that fits our use case
-
- Replace with name of sender
+
+ {sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
-
+
);
};
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,
+ onLike: PropTypes.func,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 00000000..3d455b2d
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,43 @@
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+
+
+const ChatLog = ({ entries, onLike }) => {
+ const chatEntries = (chatLog) => {
+ return chatLog.map((entry) => {
+ return (
+
+ );
+ });
+ };
+
+ return (
+
+ {chatEntries(entries)}
+
+ );
+ };
+
+ChatLog.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,
+ })
+ ).isRequired,
+ onLike: PropTypes.func,
+};
+
+export default ChatLog;
\ No newline at end of file