-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kassidy Buslach Sharks #98
base: main
Are you sure you want to change the base?
Changes from all commits
aa06118
e655c87
c8dbb68
e72e12d
9bae67a
3b22a47
c6de636
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,39 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import './App.css'; | ||
import chatMessages from './data/messages.json'; | ||
import ChatLog from './components/ChatLog'; | ||
|
||
const App = () => { | ||
console.log(chatMessages); | ||
const [chatsMessages, setChatState] = useState(chatMessages); | ||
const changeLike = (id) => { | ||
const newData = chatsMessages.map((chat) => { | ||
if (chat.id === id) { | ||
chat.liked = !chat.liked; | ||
return chat; | ||
} | ||
return chat; | ||
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you have |
||
}); | ||
return setChatState(newData); | ||
}; | ||
const sumLikes = () => { | ||
const likedTrue = chatsMessages.filter((chat) => { | ||
return chat.liked === true; | ||
}); | ||
return likedTrue.length; | ||
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this logic in a method so that you can invoke the method when line 30 renders |
||
}; | ||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chats</h1> | ||
<h3>{sumLikes()} ❤️'s</h3> | ||
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog | ||
chatsMessages={chatsMessages} | ||
onChangeLike={changeLike} | ||
></ChatLog> | ||
</main> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
|
||
const ChatEntry = (props) => { | ||
const [liked, setLike] = useState(false); | ||
const changeHeart = !liked ? '🤍' : '❤️'; | ||
const changeLike = (id) => { | ||
const likeState = setLike(!liked); | ||
props.onChangeLike(id); | ||
|
||
return likeState; | ||
}; | ||
|
||
return ( | ||
<div className="chat-entry local"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we have the class How would you use a variable to reference the different classes depending on if the ChatEntry belongs to Vladimir or Estragon? Consider checking to see if the value of sender is 'Vladimir', if it is then the value of the class should be |
||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<h2 className="entry-name">{props.sender}</h2> | ||
<section className="entry-bubble"> | ||
<p>Replace with body of ChatEntry</p> | ||
<p className="entry-time">Replace with TimeStamp component</p> | ||
<button className="like">🤍</button> | ||
<p>{props.body}</p> | ||
<p className="entry-time"> | ||
<TimeStamp time={props.timeStamp}> years ago</TimeStamp> | ||
</p> | ||
<button | ||
onClick={() => { | ||
changeLike(props.id); | ||
}} | ||
className="like" | ||
> | ||
{changeHeart} | ||
</button> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
id: PropTypes.number.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
onChangeLike: PropTypes.func.isRequired, | ||
Comment on lines
+39
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}; | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { React } from 'react'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ChatLog = (props) => { | ||
const chatMessageArray = props.chatsMessages.map((chat) => { | ||
return ( | ||
<ChatEntry | ||
sender={chat.sender} | ||
body={chat.body} | ||
timeStamp={chat.timeStamp} | ||
id={chat.id} | ||
key={chat.id} | ||
liked={chat.liked} | ||
onChangeLike={props.onChangeLike} | ||
/> | ||
); | ||
}); | ||
return chatMessageArray; | ||
}; | ||
|
||
ChatLog.propTypes = { | ||
chatsMessages: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we know the shape of the object that is in the array, we should explicitly validate the shape of the object here for an added layer of validation to prevent your protect your program from errors. Also note that you have .isRequired on arrayOf() but you'll also. need to have .isRequired on the elements inside arrayOf() ChatLog.propTypes = {
chatsMessages: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool
})).isRequired,
onChangeLike: PropTypes.func.isRequired
}; |
||
onChangeLike: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ChatLog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debugging print statements