-
Notifications
You must be signed in to change notification settings - Fork 117
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
Submission pull request #115
base: main
Are you sure you want to change the base?
Changes from all commits
a2b0ec5
8f0bba4
503b9b6
2edd7a9
bac0a77
b05fe4a
2ab0525
a707689
5d13d5a
a88fb58
83d7902
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,3 +1,4 @@ | ||
/* src/App.css */ | ||
#App { | ||
background-color: #87cefa; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
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 [totalLikes, setTotalLikes] = useState(0); | ||
|
||
const handleLikeChange = (isLiked) => { | ||
// Increment or decrement based on the liked status | ||
setTotalLikes(prevTotalLikes => isLiked ? prevTotalLikes + 1 : prevTotalLikes - 1); | ||
} | ||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chat Log</h1> | ||
<p>{totalLikes} ❤️s</p> {/* Moved the total likes display to the top */} | ||
</header> | ||
|
||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog | ||
entries={chatMessages} | ||
onLike={handleLikeChange} | ||
/> | ||
</main> | ||
|
||
</div> | ||
); | ||
}; | ||
} | ||
|
||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* src/components/ChatEntry.css */ | ||
button { | ||
background: none; | ||
color: inherit; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
import React from 'react'; | ||
import './ChatEntry.css'; | ||
|
||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
import './ChatEntry.css'; | ||
|
||
const ChatEntry = (props) => { | ||
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. Great job! |
||
const [liked, setLiked] = useState(props.liked); | ||
|
||
const toggleLiked = () => { | ||
const newLikedStatus = !liked; | ||
setLiked(newLikedStatus); | ||
|
||
// Safeguard the invocation of onLike | ||
if (props.onLike) { | ||
props.onLike(newLikedStatus); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="chat-entry local"> | ||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<section className="entry-bubble"> | ||
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. It looks like this |
||
<p>Replace with body of ChatEntry</p> | ||
<p className="entry-time">Replace with TimeStamp component</p> | ||
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. It looks like the class |
||
<button className="like">🤍</button> | ||
</section> | ||
<div className="chat-entry"> | ||
<h3>{props.sender}</h3> | ||
<p>{props.body}</p> | ||
<TimeStamp time={props.timeStamp} /> | ||
<button className="like" onClick={toggleLiked}> | ||
{liked ? '❤️' : '🤍'} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
ChatEntry.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. Yay, prop types! |
||
//Fill with correct proptypes | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
// Make onLike prop optional | ||
onLike: PropTypes.func | ||
}; | ||
|
||
export default ChatEntry; | ||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* src/components/ChatLog.css */ | ||
.chat-log { | ||
margin: auto; | ||
max-width: 50rem; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// src/components/ChatLog.js | ||
import React from 'react'; | ||
import './ChatLog.css'; | ||
import ChatEntry from './ChatEntry'; | ||
|
||
const ChatLog = (props) => { | ||
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. Excellent! |
||
|
||
const chatEntries = props.entries.map(entry => ( | ||
<ChatEntry | ||
key={entry.id} | ||
{...entry} | ||
onLike={props.onLike} | ||
/> | ||
)); | ||
|
||
return ( | ||
<div className="chat-log"> | ||
{chatEntries} | ||
</div> | ||
); | ||
} | ||
|
||
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. This would have been a great place for prop types! |
||
export default ChatLog; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// src/components/TimeStamp.js | ||
import { DateTime } from 'luxon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
|
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.
Excellent!