diff --git a/src/App.css b/src/App.css
index d97beb4e6..77d521bbe 100644
--- a/src/App.css
+++ b/src/App.css
@@ -1,9 +1,9 @@
#App {
- background-color: #87cefa;
+ background-color: #a3d5f4;
}
#App header {
- background-color: #222;
+ background-color: rgb(143, 142, 142);
color: #fff;
padding-bottom: 0.5rem;
position: fixed;
@@ -13,6 +13,14 @@
align-items: center;
}
+#App h1{
+ font-size: 60px;
+}
+
+/* #App h4{
+ padding:10px;
+} */
+
#App main {
padding-left: 2em;
padding-right: 2em;
diff --git a/src/App.js b/src/App.js
index c10859093..2a70969ec 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,19 +1,54 @@
import React from 'react';
import './App.css';
+import ChatLog from './components/ChatLog'
import chatMessages from './data/messages.json';
+import {useState} from 'react';
+// import ChatEntry from './components/ChatEntry'
-const App = () => {
- return (
-
+
+console.log(chatMessages);
+
+function App () {
+
+ const [chatData, setChatData] = useState(chatMessages)
+ const updateChatData = updatedChat => {
+ console.log({updatedChat})
+ const chats = chatData.map(chat => {
+ if(chat.id === updatedChat.id){
+
+ return updatedChat;
+ } else{
+ return chat;
+ }
+ });
+ setChatData(chats);
+ };
+
+ const calcTotalHearts = ()=>{
+ let total = 0;
+ for (let x of chatData){
+ if(x.liked === true){
+ total += 1;
+ } };
+ return total
+ }
+
+ return(
+
- Application title
+ Chat Log Between Vladimir and Estragon
+ Likes 💜
+ {calcTotalHearts()}
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
- );
-};
+ );
+ }
+
export default App;
diff --git a/src/App.test.js b/src/App.test.js
index ca75c71dd..d37f8f749 100644
--- a/src/App.test.js
+++ b/src/App.test.js
@@ -29,7 +29,7 @@ describe('Wave 03: clicking like button and rendering App', () => {
// click the first button
fireEvent.click(firstButton)
- expect(firstButton.innerHTML).toEqual('❤️')
+ expect(firstButton.innerHTML).toEqual('💜')
// check that all other buttons haven't changed
for (let i = 1; i < buttons.length; i++) {
@@ -40,13 +40,13 @@ describe('Wave 03: clicking like button and rendering App', () => {
fireEvent.click(firstButton)
expect(firstButton.innerHTML).toEqual('🤍')
fireEvent.click(firstButton)
- expect(firstButton.innerHTML).toEqual('❤️')
+ expect(firstButton.innerHTML).toEqual('💜')
fireEvent.click(firstButton)
expect(firstButton.innerHTML).toEqual('🤍')
// click the last button a couple times
fireEvent.click(lastButton)
- expect(lastButton.innerHTML).toEqual('❤️')
+ expect(lastButton.innerHTML).toEqual('💜')
fireEvent.click(lastButton)
expect(lastButton.innerHTML).toEqual('🤍')
})
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..0761026b3 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,38 @@
import React from 'react';
import './ChatEntry.css';
-import PropTypes from 'prop-types';
+
const ChatEntry = (props) => {
+ const onButtonClick = (id) => {
+ console.log('onButtonClick')
+ const updatedChat = {
+ id: props.id,
+ sender: props.sender,
+ body: props.body,
+ liked: !props.liked,
+ likeCount: props.likeCount
+ };
+ props.onUpdateChat(updatedChat);
+ };
+ const displayLikes = props.liked ? '💜' : '🤍';
+
return (
-
Replace with name of sender
+
{props.likeCount}
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {props.body} ?
+
+ {props.timeStamp}
+
+
+
+
);
};
-ChatEntry.propTypes = {
- //Fill with correct proptypes
-};
-
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..d0e1575c2
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,44 @@
+import React from 'react';
+import './ChatLog.css';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+
+const ChatLog = (props) => {
+
+ const chatDataMap = props.chats.map(item =>(
+
))
+
+ return (
+
+ {chatDataMap}
+ {/* Wave 01: Render one ChatEntry component
+ Wave 02: Render ChatLog component */}
+
+
+ ); }
+
+ChatLog.propTypes = {
+ chats:PropTypes.arrayOf(PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ liked: PropTypes.bool.isRequired,
+ timeStamp: PropTypes.string.isRequired
+
+ })),
+ onUpdateChat: PropTypes.func.isRequired,
+
+};
+
+
+
+
+export default ChatLog;
\ No newline at end of file