From af4b1365eb75b946101f3d2e352db33a2c06e6a7 Mon Sep 17 00:00:00 2001 From: Katina Carranza Date: Mon, 18 Jul 2022 06:15:52 -0700 Subject: [PATCH 1/2] Completed Waves 2 and part of 3 --- src/App.js | 32 ++++++++++++++++++----------- src/components/ChatEntry.css | 2 +- src/components/ChatEntry.js | 39 ++++++++++++++++++++++++++++++++---- src/components/ChatLog.js | 32 +++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index c10859093..d6afa266d 100644 --- a/src/App.js +++ b/src/App.js @@ -1,19 +1,27 @@ import React from 'react'; +import { useState } from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import messageDataJson from './data/messages.json'; +import ChatLog from './components/ChatLog'; -const App = () => { - return ( -
-
-

Application title

-
-
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} -
-
- ); +function App() { + const[messageData,setMessageData] = useState(chatMessages); + const[likedPosts, updateLikedPosts] = React.useState([]); + + return ( +
+
+

Application title

+
+
+ {/* Wave 01: Render one ChatEntry component + Wave 02: Render ChatLog component */} + {/* +
+
+ ); }; export default App; diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..ece5ad733 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -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..18e247df1 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,15 +1,43 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; +import { useState} from 'react'; const ChatEntry = (props) => { + const[isLiked, setLiked] = useState(false); + + const toggleLiked = () => { + setLiked(!isLiked); + } + + const like = isLiked ? '❤️': ' 🤍 '; + + class LikeButton extends React.Component{ + state = { + likes:0 + }; + render() { + return + } + } + + const addLike = () => { + let newCount = this.state.likes +1; + this.setState({ + likes: newCount + }); + }; + return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+

setLiked((prevLike) => ! prevLike)}> + {like} +

); @@ -17,6 +45,9 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { //Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..9f8963f2c --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,32 @@ +import React from 'react'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const entryComponents = props.messageData.map((entries) => { + // console.log(entries) + return ( + //
+ //

{props.sender}

+ //
+ //

{props.body}

+ //

+ // + //
+ //
+ + ); + }); + return entryComponents +}; + +ChatLog.propTypes = { + //Fill with correct proptypes + messageData: PropTypes.arrayOf(PropTypes.object), +}; + +export default ChatLog; \ No newline at end of file From c398ea47515e09e6216206670d653f7af748afe6 Mon Sep 17 00:00:00 2001 From: Katina Carranza Date: Tue, 19 Jul 2022 13:07:33 -0700 Subject: [PATCH 2/2] Completed required components for Waves 2 and 3. --- src/App.js | 23 ++++++++++++++++++++--- src/components/ChatEntry.js | 29 ++++++++++++++--------------- src/components/ChatLog.js | 11 +++-------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/App.js b/src/App.js index d6afa266d..49b3eabae 100644 --- a/src/App.js +++ b/src/App.js @@ -7,18 +7,35 @@ import ChatLog from './components/ChatLog'; function App() { const[messageData,setMessageData] = useState(chatMessages); - const[likedPosts, updateLikedPosts] = React.useState([]); - + const getCountLikes = () => { + let likes = 0; + for (const message of messageData){ + if (message.liked){ + likes += 1; + } + }; + return likes + }; + const updateLikes = (updatedData) => { + const messages = messageData.map((message) => { + if (message.id === updatedData.id) { + return updatedData + } + else return message + }); + setMessageData(messages); + } return (

Application title

+

{getCountLikes()}

{/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */} {/* +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 18e247df1..adf813b5d 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -7,35 +7,32 @@ import { useState} from 'react'; const ChatEntry = (props) => { const[isLiked, setLiked] = useState(false); + //Function to toggle Liked Heart const toggleLiked = () => { setLiked(!isLiked); } - + // Tenary Operator for Liked Heart change color const like = isLiked ? '❤️': ' 🤍 '; - class LikeButton extends React.Component{ - state = { - likes:0 + const likedMessage = () => { + const updatedMessage = { + id: props.id, + sender: props.sender, + body: props.body, + timeStamp: props.timeStamp, + liked: !props.liked, }; - render() { - return - } + props.updateLikes(updatedMessage); + setLiked((prevLike) => ! prevLike); } - const addLike = () => { - let newCount = this.state.likes +1; - this.setState({ - likes: newCount - }); - }; - return (

{props.sender}

{props.body}

-

setLiked((prevLike) => ! prevLike)}> +

{like}

@@ -45,8 +42,10 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { //Fill with correct proptypes + id: PropTypes.number.isRequired, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired }; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 9f8963f2c..803ea04eb 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -6,18 +6,13 @@ const ChatLog = (props) => { const entryComponents = props.messageData.map((entries) => { // console.log(entries) return ( - //
- //

{props.sender}

- //
- //

{props.body}

- //

- // - //
- //
); });