diff --git a/src/App.css b/src/App.css
index d97beb4e6..ed95a4284 100644
--- a/src/App.css
+++ b/src/App.css
@@ -5,6 +5,7 @@
#App header {
background-color: #222;
color: #fff;
+ padding-top: 0.5rem;
padding-bottom: 0.5rem;
position: fixed;
width: 100%;
@@ -28,6 +29,7 @@
#App header section {
background-color: #e0ffff;
+ color: black;
}
#App .widget {
diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..305b09651 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,33 @@
import './App.css';
+import ChatLog from './components/ChatLog.jsx';
+import messagesData from './data/messages.json';
+import { useState } from 'react';
const App = () => {
+ const [messageData, setMessageData] = useState(messagesData);
+
+ const toggleLiked = (messageId) => {
+ const messages = messageData.map(message => {
+ if (message.id === messageId) {
+ return { ...message, liked: !message.liked };
+ } else {
+ return message; // message like status not changed
+ }
+ });
+ setMessageData(messages);
+ };
+ const totalLikes = messageData.filter(message => message.liked).length;
return (
- Application title
+ React Chatlog
+
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index 15c56f96b..b3ffe4ae5 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,20 +1,33 @@
import './ChatEntry.css';
+import TimeStamp from './TimeStamp.jsx';
+import PropTypes from 'prop-types';
-const ChatEntry = () => {
+const ChatEntry = ({id, sender, body, timeStamp, liked, onLikeToggle}) => {
+ const likeButtonClicked = () => {
+ onLikeToggle(id);
+ };
+ const heartColor = liked ? '❤️' : '🤍';
return (
-
Replace with name of sender
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
+
+
);
};
ChatEntry.propTypes = {
- // Fill with correct proptypes
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ id: PropTypes.number,
+ liked: PropTypes.bool,
+ onLikeToggle: PropTypes.func
};
-export default ChatEntry;
+export default ChatEntry;
\ No newline at end of file
diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css
index 378848d1f..1edce22f2 100644
--- a/src/components/ChatLog.css
+++ b/src/components/ChatLog.css
@@ -1,4 +1,4 @@
.chat-log {
margin: auto;
- max-width: 50rem;
+ max-width: 50rem
}
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..23c5ccd7e
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,39 @@
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry.jsx';
+
+const ChatLog = (props) => {
+ const messageComponents = props.entries.map(message => {
+ return (
+
+ );
+ });
+
+ return (
+ <>
+ {messageComponents}
+ >
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ id: PropTypes.number,
+ liked: PropTypes.bool
+ })
+ ).isRequired,
+ onLikeToggle: PropTypes.func
+};
+export default ChatLog;
\ No newline at end of file
diff --git a/src/data/messages.json b/src/data/messages.json
index 64fdb053c..67cc5eb39 100644
--- a/src/data/messages.json
+++ b/src/data/messages.json
@@ -188,4 +188,4 @@
"timeStamp":"2018-05-29T23:17:34+00:00",
"liked": false
}
-]
+]
\ No newline at end of file