From b91c26979adc182fbeda5255b984fd6791879325 Mon Sep 17 00:00:00 2001 From: Erina Perez Date: Tue, 20 Jun 2023 14:15:01 -0700 Subject: [PATCH 1/5] Completed Wave 01 --- src/App.js | 13 ++++++++++--- src/components/ChatEntry.js | 12 ++++++++---- src/components/ChatLog.js | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index c10859093..f9133e1af 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,23 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatEntry from './components/ChatEntry'; const App = () => { + // console.log((chatMessages)) + const testMessage = chatMessages[0]; return (
-

Application title

+

Chat 123

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + + +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..0d499ff9e 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,14 +1,18 @@ import React from 'react'; import './ChatEntry.css'; -import PropTypes from 'prop-types'; +import chatMessages from '../data/messages.json'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { + const { sender, body, timeStamp } = props; return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{body}

+

+ +

diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..fe4884fd8 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,4 @@ +import React from "react"; +import PropTypes from 'prop-types'; +import ChatEntry from "./ChatEntry"; + From 4a06f2f0b0008f9bd262dfb1867f729849831611 Mon Sep 17 00:00:00 2001 From: Erina Perez Date: Tue, 20 Jun 2023 22:25:44 -0700 Subject: [PATCH 2/5] Completed wave 02 --- src/App.js | 16 ++++++---------- src/components/ChatEntry.js | 10 +++++++--- src/components/ChatLog.css | 2 ++ src/components/ChatLog.js | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/App.js b/src/App.js index f9133e1af..5620b3746 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,19 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; -import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog.js'; const App = () => { - // console.log((chatMessages)) - const testMessage = chatMessages[0]; return (
-

Chat 123

+

🤖 Chatterbot 🤖

- - - + +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 0d499ff9e..597448c75 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,12 +1,12 @@ import React from 'react'; import './ChatEntry.css'; -import chatMessages from '../data/messages.json'; import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; const ChatEntry = (props) => { const { sender, body, timeStamp } = props; return ( -
+

{sender}

{body}

@@ -20,7 +20,11 @@ const ChatEntry = (props) => { }; 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 }; export default ChatEntry; diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1f..02100de18 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -2,3 +2,5 @@ margin: auto; max-width: 50rem; } + + diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index fe4884fd8..82227e233 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -1,4 +1,34 @@ -import React from "react"; +import React from 'react'; +import './ChatLog.css'; import PropTypes from 'prop-types'; -import ChatEntry from "./ChatEntry"; +import ChatEntry from './ChatEntry.js'; +const ChatLog = (props) => { + const chatComponents = props.entries.map(entry => { + return ( + + ); + }); + return ( +
+ {chatComponents} +
+ ); +} + +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 + })) +}; + +export default ChatLog; \ No newline at end of file From e621905471f9ca0de58af7701250722286caad6c Mon Sep 17 00:00:00 2001 From: Erina Perez Date: Fri, 23 Jun 2023 09:46:54 -0700 Subject: [PATCH 3/5] Completed wave 3 --- src/App.css | 3 +++ src/App.js | 28 ++++++++++++++++++++-- src/components/ChatEntry.js | 47 +++++++++++++++++++++++++------------ src/components/ChatLog.js | 5 ++-- 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/App.css b/src/App.css index d97beb4e6..e73d4e501 100644 --- a/src/App.css +++ b/src/App.css @@ -28,6 +28,9 @@ #App header section { background-color: #e0ffff; + color: #222; + font-size:1.0em; + font-weight: bold; } #App .widget { diff --git a/src/App.js b/src/App.js index 5620b3746..6022d17c6 100644 --- a/src/App.js +++ b/src/App.js @@ -2,18 +2,42 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; import ChatLog from './components/ChatLog.js'; +import { useState } from 'react'; const App = () => { + const [entries, setEntriesData] = useState(chatMessages); + const updateLikedCount = (id) => { + setEntriesData((prev) => { + return prev.map((entry) => { + if(id === entry.id) { + return { + ...entry, + liked: !entry.liked, + }; + } else { + return entry; + } + }); + }); + } + const totalLikesTally = entries.reduce((total, entry) => { + if (entry.liked === true) { + total += 1; + } + return total; + }, 0); + return (

🤖 Chatterbot 🤖

+
{totalLikesTally} ❤️s
- + entries={entries} + updateLikedCount={updateLikedCount}/>
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 597448c75..4202e6824 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -4,27 +4,44 @@ import TimeStamp from './TimeStamp'; import PropTypes from 'prop-types'; const ChatEntry = (props) => { - const { sender, body, timeStamp } = props; - return ( -
-

{sender}

-
-

{body}

-

- -

- -
-
- ); -}; + const onLikeButtonClick = () => { + props.updateLikedCount(props.id); + } + + // const updateChat = { + // id: props.id, + // sender: props.sender, + // body: props.body, + // timeStamp: props.timeStamp, + // liked: !props.liked, + // }; + // }; + // props.onLike(updateChat); + + const formatMessages = props.sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote'; + return ( +
+

{props.sender}

+
+

{props.body}

+

+ +

+ +
+
+ )}; + ChatEntry.propTypes = { id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, - liked: PropTypes.bool.isRequired + liked: PropTypes.bool, + onUpdate: PropTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 82227e233..48a379fb2 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -11,8 +11,9 @@ const ChatLog = (props) => { sender={entry.sender} body={entry.body} liked={entry.liked} - time={entry.timeStamp}/> - ); + timeStamp={entry.timeStamp} + updateLikedCount={props.updateLikedCount}/> + ); }); return (
From 0332fd8fcbf6cd0acf32eb4b9ae970c9562535c9 Mon Sep 17 00:00:00 2001 From: Erina Perez Date: Fri, 23 Jun 2023 09:58:45 -0700 Subject: [PATCH 4/5] Cleaned up and removed comments, local-remote working --- src/App.js | 5 ++--- src/components/ChatEntry.css | 2 +- src/components/ChatEntry.js | 13 +------------ 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/App.js b/src/App.js index 6022d17c6..fc7fbbb14 100644 --- a/src/App.js +++ b/src/App.js @@ -13,8 +13,7 @@ const App = () => { return { ...entry, liked: !entry.liked, - }; - } else { + }; } else { return entry; } }); @@ -43,4 +42,4 @@ const App = () => { ); }; -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 05c3baa44..40aabde1c 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -27,7 +27,7 @@ button { } .chat-entry .entry-bubble:hover { - background-color: #fefea2; + background-color: hsl(60, 98%, 82%); } .chat-entry .entry-name { diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 4202e6824..230237afc 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -8,16 +8,6 @@ const ChatEntry = (props) => { props.updateLikedCount(props.id); } - // const updateChat = { - // id: props.id, - // sender: props.sender, - // body: props.body, - // timeStamp: props.timeStamp, - // liked: !props.liked, - // }; - // }; - // props.onLike(updateChat); - const formatMessages = props.sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote'; return (
@@ -34,7 +24,6 @@ const ChatEntry = (props) => {
)}; - ChatEntry.propTypes = { id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, @@ -44,4 +33,4 @@ ChatEntry.propTypes = { onUpdate: PropTypes.func }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file From 5d16746537faf0a07a1216886150ea935d44575c Mon Sep 17 00:00:00 2001 From: Erina Perez Date: Fri, 23 Jun 2023 10:14:42 -0700 Subject: [PATCH 5/5] Fixes for Learn submission --- src/components/ChatLog.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 48a379fb2..4441a9ad6 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -6,7 +6,8 @@ import ChatEntry from './ChatEntry.js'; const ChatLog = (props) => { const chatComponents = props.entries.map(entry => { return ( - { ); }); return ( -
- {chatComponents} -
- ); -} +
+ {chatComponents} +
+ ); +}; ChatLog.propTypes = { entries: PropTypes.arrayOf(PropTypes.shape({