diff --git a/.prettierrc.json b/.prettierrc.json
new file mode 100644
index 000000000..544138be4
--- /dev/null
+++ b/.prettierrc.json
@@ -0,0 +1,3 @@
+{
+ "singleQuote": true
+}
diff --git a/src/App.css b/src/App.css
index d97beb4e6..cc76bfac1 100644
--- a/src/App.css
+++ b/src/App.css
@@ -26,8 +26,15 @@
display: inline-block;
}
+#App header h2 {
+ background-color: honeydew;
+ color: #222;
+ display: block;
+ font-size: x-large;
+}
+
#App header section {
- background-color: #e0ffff;
+ background-color: #d50e68;
}
#App .widget {
@@ -35,40 +42,40 @@
line-height: 0.5em;
border-radius: 10px;
color: black;
- font-size:0.8em;
+ font-size: 0.8em;
padding-left: 1em;
padding-right: 1em;
}
#App #heartWidget {
font-size: 1.5em;
- margin: 1em
+ margin: 1em;
}
#App span {
- display: inline-block
+ display: inline-block;
}
.red {
- color: #b22222
+ color: #b22222;
}
.orange {
- color: #e6ac00
+ color: #e6ac00;
}
.yellow {
- color: #e6e600
+ color: #e6e600;
}
.green {
- color: green
+ color: green;
}
.blue {
- color: blue
+ color: blue;
}
.purple {
- color: purple
-}
\ No newline at end of file
+ color: purple;
+}
diff --git a/src/App.js b/src/App.js
index c10859093..2b05cbe9e 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,52 @@
-import React from 'react';
+import React, { useState } from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatLog from './components/ChatLog';
const App = () => {
+ const chatData = chatMessages;
+
+ const [entryData, setEntryData] = useState(chatData);
+
+ const updateEntryData = (updatedEntry) => {
+ const entries = entryData.map((entry) => {
+ if (entry.id === updatedEntry.id) {
+ return updatedEntry;
+ } else {
+ return entry;
+ }
+ });
+
+ setEntryData(entries);
+ };
+
+ const [likeCount, setLikeCount] = useState(0);
+
+ const updateLikes = (isLiked) => {
+ if (isLiked) {
+ setLikeCount((prevState) => prevState + 1);
+ } else {
+ setLikeCount((prevState) => prevState - 1);
+ }
+ };
+
return (
- Application title
+
+ Chat between {chatData[0].sender} and {chatData[1].sender}
+
+ {likeCount} ❤️s
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
+
+
);
diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css
index 05c3baa44..c2a28bf70 100644
--- a/src/components/ChatEntry.css
+++ b/src/components/ChatEntry.css
@@ -1,11 +1,11 @@
button {
background: none;
- color: inherit;
- border: none;
- padding: 10px;
- font: inherit;
- cursor: pointer;
- outline: inherit;
+ color: inherit;
+ border: none;
+ padding: 10px;
+ font: inherit;
+ cursor: pointer;
+ outline: inherit;
}
.chat-entry {
@@ -77,7 +77,7 @@ button {
}
.chat-entry.remote .entry-bubble {
- background-color: #e0ffff;
+ background-color: #a4f9ad;
margin-left: auto;
margin-right: 0;
}
@@ -97,4 +97,4 @@ button {
.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
-}
\ No newline at end of file
+}
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..9def16990 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,49 @@
-import React from 'react';
+import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
+ const onLikeButtonClick = () => {
+ const updateEntry = {
+ id: props.id,
+ sender: props.sender,
+ body: props.body,
+ timeStamp: props.timeStamp,
+ liked: !props.liked,
+ };
+ props.onUpdateEntryData(updateEntry);
+ props.updateLikes(!props.liked);
+ };
+
+ const likeHeart = props.liked ? '❤️' : '🤍';
+
+ const chatClass =
+ props.sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote';
+
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.isRequired,
+ liked: PropTypes.bool,
+ onUpdateEntryData: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css
index 378848d1f..68e4371ae 100644
--- a/src/components/ChatLog.css
+++ b/src/components/ChatLog.css
@@ -1,4 +1,5 @@
.chat-log {
margin: auto;
- max-width: 50rem;
+ max-width: 5rem;
+ color: darkgreen;
}
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..e66ce6ce3
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = ({ entries, onUpdateEntryData, updateLikes }) => {
+ return (
+
+ {entries.map((entry) => (
+
+ ))}
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ liked: PropTypes.bool
+ })),
+ onUpdateEntryData: PropTypes.func.isRequired,
+
+};
+
+export default ChatLog;