From 085695331849ed85122829522e6d1dd58a31d6f1 Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Thu, 15 Dec 2022 15:08:19 -0800 Subject: [PATCH 1/6] finished wave 01 --- src/App.css | 2 +- src/App.js | 5 ++++- src/components/ChatEntry.js | 14 ++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/App.css b/src/App.css index d97beb4e6..439a81e37 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,5 @@ #App { - background-color: #87cefa; + background-color: #E6E6FA; } #App header { diff --git a/src/App.js b/src/App.js index c10859093..f064003a0 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,19 @@ import React from 'react'; import './App.css'; +import ChatEntry from './components/ChatEntry'; import chatMessages from './data/messages.json'; const App = () => { return (
-

Application title

+

Heard it Through The Ivy Vine

{/* 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..3d2e17b05 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,28 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { 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 + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, }; export default ChatEntry; From 5b30866bd327dadf5d8da0302b78d77695bf304b Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Fri, 16 Dec 2022 16:40:07 -0800 Subject: [PATCH 2/6] finished wave 02 --- src/App.js | 7 ++++--- src/components/ChatLog.js | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index f064003a0..1c6e7daa5 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,7 @@ import React from 'react'; import './App.css'; -import ChatEntry from './components/ChatEntry'; +// import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; import chatMessages from './data/messages.json'; const App = () => { @@ -12,8 +13,8 @@ const App = () => {
{/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */} - - + {/* */} +
); diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..0d70d32fc --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,27 @@ +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const entryComponants = props.entries.map(message => { + return( +
  • + ); + }); + + return ( +
    +
      + {entryComponants} +
    +
    + + ); +}; + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired, +}; + +export default ChatLog; \ No newline at end of file From 727589ab22dfb6ed6b4b2b9de990242f3b9dfa58 Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Fri, 16 Dec 2022 16:54:28 -0800 Subject: [PATCH 3/6] fixed css so that vlads messages are local and others are remote --- src/App.js | 3 --- src/components/ChatEntry.js | 7 ++++++- src/components/ChatLog.css | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 1c6e7daa5..9dca987b2 100644 --- a/src/App.js +++ b/src/App.js @@ -11,9 +11,6 @@ const App = () => {

    Heard it Through The Ivy Vine

    - {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} - {/* */}
    diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 3d2e17b05..f389d37b5 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -4,8 +4,13 @@ import PropTypes from 'prop-types'; import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { + let isLocal = 'local'; + if (props.sender !== 'Vladimir'){ + isLocal = 'remote'; + } + return ( -
    +

    {props.sender}

    {props.body}

    diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1f..dfba563dd 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -2,3 +2,7 @@ margin: auto; max-width: 50rem; } + +.chat-log ul{ + list-style: none; +} \ No newline at end of file From 23744d7cfda134f83d5a4e5d5433fe3c084c4f90 Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Fri, 16 Dec 2022 20:46:35 -0800 Subject: [PATCH 4/6] finished wave 03 --- src/App.js | 38 +++++++++++++++++++++++++++++++++++-- src/components/ChatEntry.js | 19 ++++++++++++++++++- src/components/ChatLog.js | 12 +++++++++++- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 9dca987b2..8b1032496 100644 --- a/src/App.js +++ b/src/App.js @@ -3,15 +3,49 @@ import './App.css'; // import ChatEntry from './components/ChatEntry'; import ChatLog from './components/ChatLog'; import chatMessages from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [entries, setEntries] = useState(chatMessages) + + const updateMessages = (updatedMessage) => { + const messages = entries.map(message => { + if (message.id === updatedMessage.id) { + return updatedMessage; + } + else { + return message + } + }); + setEntries(messages); + }; + + const totalLikes = (entries) => { + let likes = 0 + for (let message of entries){ + if (message.liked === true){ + likes +=1; + } + } + return `${likes} ❤️s`; + }; + return (

    Heard it Through The Ivy Vine

    -
    +
    +
    +
    {totalLikes(entries)}
    +
    +
    + +
    - +
    ); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index f389d37b5..a312efabc 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -9,6 +9,20 @@ const ChatEntry = (props) => { isLocal = 'remote'; } + const toggleLike = () => { + const updatedMessage = { + sender: props.sender, + id: props.id, + body: props.body, + timeStamp: props.timeStamp, + liked: !props.liked, + }; + props.onToggleLike(updatedMessage); + } + + + const heart = props.liked ? '❤️' : '🤍'; + return (

    {props.sender}

    @@ -17,7 +31,7 @@ const ChatEntry = (props) => {

    - +
    ); @@ -25,9 +39,12 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { + id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + onToggleLike : PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 0d70d32fc..6d3f6d6a1 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -6,7 +6,16 @@ import PropTypes from 'prop-types'; const ChatLog = (props) => { const entryComponants = props.entries.map(message => { return( -
  • +
  • + +
  • ); }); @@ -22,6 +31,7 @@ const ChatLog = (props) => { ChatLog.propTypes = { entries: PropTypes.array.isRequired, + onToggleLike: PropTypes.func.isRequired, }; export default ChatLog; \ No newline at end of file From 314616c2e28869b53ff67a467c7b2cfa86d82368 Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Thu, 22 Dec 2022 15:43:31 -0800 Subject: [PATCH 5/6] reoved is required from id and liked becuase it looks like those dont always get passed in with the tests --- src/components/ChatEntry.js | 6 +++--- src/components/ChatLog.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index a312efabc..65337647e 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -39,12 +39,12 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { - id: PropTypes.number.isRequired, + id: PropTypes.number, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, - liked: PropTypes.bool.isRequired, - onToggleLike : PropTypes.func.isRequired, + liked: PropTypes.bool, + onToggleLike : PropTypes.func, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 6d3f6d6a1..fb650ccf7 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -31,7 +31,7 @@ const ChatLog = (props) => { ChatLog.propTypes = { entries: PropTypes.array.isRequired, - onToggleLike: PropTypes.func.isRequired, + onToggleLike: PropTypes.func, }; export default ChatLog; \ No newline at end of file From 872729d2574b9a192ae0fec064ba303faa18200b Mon Sep 17 00:00:00 2001 From: ivystrayed Date: Thu, 22 Dec 2022 15:56:18 -0800 Subject: [PATCH 6/6] had to change the key for the message list back to index from message.id becuase sometimes the backend info given does not include id --- src/components/ChatLog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index fb650ccf7..bd951684d 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -4,9 +4,9 @@ import ChatEntry from './ChatEntry'; import PropTypes from 'prop-types'; const ChatLog = (props) => { - const entryComponants = props.entries.map(message => { + const entryComponants = props.entries.map((message, index) => { return( -
  • +