diff --git a/src/App.css b/src/App.css
index d97beb4e..7bf48e05 100644
--- a/src/App.css
+++ b/src/App.css
@@ -18,6 +18,7 @@
padding-right: 2em;
padding-bottom: 5rem;
padding-top: 10rem;
+ text-align: center;
}
#App h1 {
@@ -31,7 +32,7 @@
}
#App .widget {
- display: inline-block;
+ display: block;
line-height: 0.5em;
border-radius: 10px;
color: black;
@@ -42,7 +43,16 @@
#App #heartWidget {
font-size: 1.5em;
- margin: 1em
+ margin: 1em;
+ padding-top: 1em;
+ padding-bottom: 0.8em;
+}
+
+#App header h1,
+#App #heartWidget {
+ line-height: 3rem;
+ margin: 0;
+ padding: 0;
}
#App span {
diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684..14848ec7 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,17 +1,48 @@
import './App.css';
+import messages from './data/messages.json';
+import ChatLog from './components/ChatLog';
+import { useState } from 'react';
+
+const SENDER_COLORS = {
+ Vladimir: 'red',
+ Estragon: 'green',
+};
const App = () => {
+ const [chatMessages, setChatMessages] = useState(messages);
+
+ const toggleLikeChoice = (id) => {
+ setChatMessages(chatMessages => {
+ return chatMessages.map(message => {
+ if (message.id === id) {
+ return { ...message, liked: !message.liked };
+ } else {
+ return message;
+ }
+ });
+ });
+ };
+
+ const countLikes = chatMessages.filter(msg => msg.liked).length;
+
+ const participants = Array.from(new Set(chatMessages.map(msg => msg.sender)));
+ const headerTitle = `Chat between ${participants.join(' and ')}`;
+
return (
- Application title
+ {headerTitle}
+
-
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
+
);
};
-export default App;
+export default App;
\ No newline at end of file
diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css
index 05c3baa4..e4ebd6ed 100644
--- a/src/components/ChatEntry.css
+++ b/src/components/ChatEntry.css
@@ -36,12 +36,19 @@ button {
}
.chat-entry .entry-time {
+ display: block;
color: #bbb;
font-size: x-small;
margin-bottom: 0.1rem;
margin-right: 0.5rem;
}
+.chat-entry .like {
+ display: block;
+ margin-top: 0.3rem;
+ margin-left: auto;
+}
+
/* Chat bubble arrow styling */
.chat-entry .entry-bubble::before {
content: '';
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index fe05efa0..f163ca30 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,21 +1,32 @@
import './ChatEntry.css';
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
-const ChatEntry = () => {
+const ChatEntry = ({ id, sender, body, timeStamp, toggleLikeChoice, liked, color }) => {
+ const isLocal = sender === 'Vladimir';
return (
// Replace the outer tag name with a semantic element that fits our use case
-
- Replace with name of sender
-
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+
+ {sender}
+
+ {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,
+ toggleLikeChoice: PropTypes.func,
+ color: PropTypes.string
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 00000000..422f3bab
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,42 @@
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, toggleLikeChoice = () => {}, senderColors = {} }) => {
+ const chatEntryComponents = entries.map(entry => {
+ return (
+
+ );
+ });
+
+ return (
+
+ {chatEntryComponents}
+
+ );
+};
+
+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,
+ toggleLikeChoice: PropTypes.func,
+ senderColors: PropTypes.object,
+};
+
+export default ChatLog;
\ No newline at end of file