diff --git a/src/App.css b/src/App.css
index d97beb4e6..f56752a0a 100644
--- a/src/App.css
+++ b/src/App.css
@@ -28,6 +28,7 @@
#App header section {
background-color: #e0ffff;
+ color: black;
}
#App .widget {
diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..898aea08a 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,15 +1,60 @@
+import { useState } from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
+import messages from './data/messages.json';
-const App = () => {
+
+const calculateTotalLikeCount = (chat) => {
+ return chat.reduce((total, chat) => {
+ return total + (chat.liked ? 1 : 0);
+ }, 0);
+};
+
+const localSender = messages[0].sender;
+let remoteSender = 'Unknown';
+
+for (const message of messages) {
+ if (message.sender !== localSender) {
+ remoteSender = message.sender;
+ break; // Stop once other sender is found
+ }
+}
+
+
+const App =() => {
+ const [chat, setChat] = useState(messages);
+
+ const handleLikeButtom = (id) => {
+ setChat(chat => {
+ return chat.map(chat => {
+ if (chat.id === id) {
+ return { ...chat, liked: !chat.liked };
+ } else {
+ return chat;
+ }
+ });
+ });
+ };
+ const totalLikes = calculateTotalLikeCount(chat);
return (
-
Replace with name of sender
+
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.body}
+
+
);
};
ChatEntry.propTypes = {
- // Fill with correct proptypes
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
+ onLiked: PropTypes.func.isRequired,
+ localSender: PropTypes.string.isRequired
};
-export default ChatEntry;
+export default ChatEntry;
\ No newline at end of file
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..12d4d576e
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,46 @@
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+
+const ChatLog = (props) => {
+ const chatentrycomponents = props.entries.map((entries, index) => {
+ return (
+
+ );
+ });
+
+ return (
+
+
+ {chatentrycomponents}
+
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
+ })
+ ).isRequired,
+
+ onLiked: PropTypes.func.isRequired,
+ localSender: PropTypes.string.isRequired,
+};
+
+export default ChatLog;
\ No newline at end of file