-
Notifications
You must be signed in to change notification settings - Fork 626
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
Ruby- Mikayla H #68
base: main
Are you sure you want to change the base?
Ruby- Mikayla H #68
Changes from all commits
8b94a09
a1653fd
ed155da
3a94d04
0d8da7e
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,19 +1,49 @@ | ||
import React from 'react'; | ||
import './App.css'; | ||
import chatMessages from './data/messages.json'; | ||
import ChatEntry from './components/ChatEntry'; | ||
import ChatLog from './components/ChatLog'; | ||
import { useState } from 'react'; | ||
|
||
|
||
|
||
//use state | ||
// create func to update likes | ||
//creat func to count likes | ||
|
||
|
||
const App = () => { | ||
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 [entries, setEntries] = useState(chatMessages); | ||
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, state! |
||
|
||
const updateLike = (entryId) => { | ||
const updatedEntries = entries.map((entry) => { | ||
if (entry.id === entryId) { | ||
return { ...entry, liked: !entry.liked }; | ||
} | ||
return entry; | ||
}); | ||
|
||
setEntries(updatedEntries); | ||
} | ||
const newLikedCount = entries.filter( | ||
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. Minor note: this line is not indented correctly. |
||
(entry) => entry.liked === true).length; | ||
|
||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1> Mikayla's Application</h1> | ||
<h2>{newLikedCount} ❤️s</h2> | ||
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog entries={entries} | ||
updateLike={updateLike} /> | ||
</main> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
|
||
|
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 = (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 changeLike = props.liked ? '❤️' : '🤍'; | ||
return ( | ||
<div className="chat-entry local"> | ||
<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}/></p> | ||
<button className="like" onClick={() => { | ||
props.updateLike(props.id)} | ||
}>{changeLike}</button> | ||
</section> | ||
</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! It would be good to make sure all of the props are here (like id). |
||
//Fill with correct proptypes | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
updateLike: PropTypes.func.isRequired, | ||
}; | ||
|
||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types' | ||
|
||
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 be a great place to add the ChatLog.css import! |
||
|
||
|
||
const ChatLog = (props) => { | ||
const {entries, updateLike} = props; | ||
return ( | ||
<div className='chat-log'> | ||
{entries.map((entry) => ( | ||
<ChatEntry | ||
id={entry.id} | ||
key={entry.id} | ||
sender={entry.sender} | ||
body={entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} | ||
updateLike={updateLike} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
export default ChatLog; | ||
|
||
|
||
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. Yay, 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, | ||
}) | ||
), | ||
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. Remember to add an |
||
updateLike: PropTypes.func.isRequired | ||
}; |
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.
This import is not needed! It's best practice to remove unused imports before submitting projects.