-
Notifications
You must be signed in to change notification settings - Fork 153
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
Alexis Miller - Cheetahs #121
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"workbench.colorCustomizations": { | ||
"activityBar.background": "#113420", | ||
"titleBar.activeBackground": "#18492D", | ||
"titleBar.activeForeground": "#F4FBF7" | ||
} | ||
} |
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 = () => { | ||
const [messageData, setMessageData] = useState(chatMessages); | ||
|
||
const onLike = (id) => { | ||
setMessageData((messageData) => | ||
messageData.map((message) => { | ||
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'd recommend trying to avoid having too many nested functions. This totally works, but it doesn't have the best readability. more readable = easier to maintain 😌 |
||
if (message.id === id) { | ||
return { ...message, liked: !message.liked }; | ||
} else { | ||
return message; | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
const calcTotalLikes = (messageData) => { | ||
return messageData.reduce((total, message) => { | ||
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. nice usage of reduce()! 👏🏾 |
||
return total + message.liked; | ||
}, 0); | ||
}; | ||
|
||
const totalLikes = calcTotalLikes(messageData); | ||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chat Log</h1> | ||
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<h2>{totalLikes} ❤️s </h2> | ||
<ChatLog entries={messageData} onLike={onLike}></ChatLog> | ||
</main> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import React from 'react'; | ||
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
|
||
const ChatEntry = ({ id, sender, body, timeStamp, liked, onLike }) => { | ||
const heartStatus = liked ? '❤️' : '🤍'; | ||
|
||
const ChatEntry = (props) => { | ||
return ( | ||
<div className="chat-entry local"> | ||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<h2 className="entry-name">{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>{body}</p> | ||
<p className="entry-time"> | ||
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 would recommend using a div here instead of a paragraph tag since it isn't a good semantic representation of the time stamp content. Or maybe not wrapping the component in another tag at all. |
||
<TimeStamp time={timeStamp} /> | ||
</p> | ||
<button className="like" onClick={() => onLike(id)}> | ||
{heartStatus} | ||
</button> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
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, | ||
onLike: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ChatLog = ({ entries, onLike }) => { | ||
return ( | ||
<ul> | ||
{entries.map((entry) => ( | ||
<ChatEntry | ||
key={entry.id} | ||
id={entry.id} | ||
sender={entry.sender} | ||
body={entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} | ||
onLike={onLike} | ||
></ChatEntry> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
ChatLog.propTypes = { | ||
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. Good prop types 👍🏾 |
||
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, | ||
}) | ||
), | ||
onLike: 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.
you don't have to pass
messageData
as an argument here since it's globally available inApp
.