diff --git a/src/App.css b/src/App.css
index d97beb4e6..5c638ee15 100644
--- a/src/App.css
+++ b/src/App.css
@@ -28,6 +28,10 @@
#App header section {
background-color: #e0ffff;
+ color: black;
+ font-size: 1.5em;
+ padding-top: 0.5rem;
+ padding-bottom: 0.5rem;
}
#App .widget {
diff --git a/src/App.js b/src/App.js
index c10859093..cf90d9b50 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,46 @@
-import React from 'react';
+import React, {useState} from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatLog from './components/ChatLog.js'
+
const App = () => {
+ const localUser = chatMessages[0].sender
+ const remoteUser = chatMessages[1].sender
+
+ const [chatData, setChatData] = useState(chatMessages);
+
+ const onUpdateChat = (updatedChat) => {
+ const messages = chatData.map(chat => {
+ if (chat.id === updatedChat.id) {
+ return updatedChat;
+ } else {
+ return chat;
+ }
+ });
+
+ setChatData(messages);
+ };
+
+ let totalLikes = 0
+ for (const message of chatData) {
+ if (message.liked) {
+ totalLikes +=1
+ };
+ };
+
+
return (
- Application title
+ Chat between {localUser} and {remoteUser}
+
- {/* 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..9d6b2d905 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,43 @@
import React from 'react';
import './ChatEntry.css';
+import TimeStamp from './TimeStamp.js';
import PropTypes from 'prop-types';
const ChatEntry = (props) => {
+ const timeEntry=props.timeStamp
+
+ const onLikeButtonClick = () => {
+ const updatedChat = {
+ id: props.id,
+ sender: props.sender,
+ body: props.body,
+ timeStamp: props.timeStamp,
+ liked: !props.liked
+ };
+
+ props.onUpdateChat(updatedChat);
+ };
+
+ const heartColor = props.liked ? '❤️' : '🤍';
+
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
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool,
+ onUpdateChat: PropTypes.func.isRequired
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..d676b8174
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,43 @@
+import React from 'react';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry.js'
+
+const ChatLog = (props) => {
+ if (!props.chatData) {
+ return null
+ }
+ const ChatLogEntries = props.chatData.map((entry) => {
+ return (
+
+
+
+ );
+ });
+
+ return (
+
+ {ChatLogEntries}
+
+ );
+};
+
+ChatLog.propTypes = {
+ chat: PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ senderData: PropTypes.string.isRequired,
+ bodyData: PropTypes.string.isRequired,
+ likedData: PropTypes.bool.isRequired
+ })),
+ onUpdateChat: PropTypes.func.isRequired
+};
+
+export default ChatLog