diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 000000000..7a73a41bf
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,2 @@
+{
+}
\ No newline at end of file
diff --git a/src/App.css b/src/App.css
index d97beb4e6..4b3e77dec 100644
--- a/src/App.css
+++ b/src/App.css
@@ -35,7 +35,7 @@
line-height: 0.5em;
border-radius: 10px;
color: black;
- font-size:0.8em;
+ font-size: 0.8em;
padding-left: 1em;
padding-right: 1em;
}
diff --git a/src/App.js b/src/App.js
index c10859093..d87997d1b 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,15 +1,40 @@
-import React from 'react';
+import { React, useState } from 'react';
import './App.css';
+import ChatEntry from './components/ChatEntry';
import chatMessages from './data/messages.json';
-
+import ChatLog from './components/ChatLog'
const App = () => {
+
+ const [messageData, setMessageData] = useState(chatMessages)
+ const [likeData, setLikeData] = useState(0)
+
+ const updateMessage = (messageToUpdate) => {
+ const entries = messageData.map((message) => {
+ if (message.id === messageToUpdate.id) {
+ return messageToUpdate
+ }
+ else if (messageToUpdate) {
+ setLikeData(likeData + 1);
+
+ } else {
+ setLikeData(likeData - 1);
+ };
+ })
+ };
+
return (
- Application title
+ Chat Log
+ Like count {likeData} ❤️s
- {/* Wave 01: Render one ChatEntry component
+ {
+
+
+
+ /* 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..7fd093393 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 {
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..d4f3b4069 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,15 +1,39 @@
-import React from 'react';
+import { React, useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
+const ChatEntry = ({ sender, body, liked, timeStamp, id, onUpdateMessage }) => {
+ const [isLiked, setIsLiked] = useState(liked);
+
+ if (isLiked) {
+ console.log('is liked');
+ } else {
+ console.log('is unliked');
+ }
+
+ const updateLiked = () => {
+ console.log('updating heart')
+ setIsLiked(!isLiked);
+ onUpdateMessage({
+ sender: sender,
+ body: body,
+ timeStamp: timeStamp,
+ id: id,
+ isLiked: !isLiked,
+ })
+ };
+
+ const heartColor = isLiked ? '❤️' : '🤍';
-const ChatEntry = (props) => {
return (
-
Replace with name of sender
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
+
);
@@ -17,6 +41,13 @@ const ChatEntry = (props) => {
ChatEntry.propTypes = {
//Fill with correct proptypes
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ id: PropTypes.number.isRequired,
+ isLiked: PropTypes.bool.isRequired,
+ onUpdateMessage: PropTypes.func.isRequired
+
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..b6fb47c05
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,40 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+
+const ChatLog = ({ entries, id, liked, onUpdateMessage }) => {
+
+ return (
+
+ {entries.map(chat => {
+ return (
+
+ );
+ })}
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ sender: PropTypes.string,
+ body: PropTypes.string,
+ timeStamp: PropTypes.string,
+ id: PropTypes.number.isRequired,
+ liked: PropTypes.bool.isRequired,
+ onUpdateMessage: PropTypes.func.isRequire
+
+ })
+ )
+}
+
+export default ChatLog;
\ No newline at end of file