-
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
Kunzite - Allie S. #107
base: main
Are you sure you want to change the base?
Kunzite - Allie S. #107
Changes from all commits
d12667b
1424b24
e90d7fc
8506818
8a6f975
314d80e
753de65
800cb23
24c7311
c8a0b9f
bb0abe4
92c2006
6b24159
44a6144
bf0af01
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,53 @@ | ||||||||
import React from 'react'; | ||||||||
import './App.css'; | ||||||||
import chatMessages from './data/messages.json'; | ||||||||
import ChatLog from './components/ChatLog'; | ||||||||
import { useState } from 'react'; | ||||||||
|
||||||||
const App = () => { | ||||||||
return ( | ||||||||
<div id="App"> | ||||||||
<header> | ||||||||
<h1>Application title</h1> | ||||||||
</header> | ||||||||
<main> | ||||||||
{/* Wave 01: Render one ChatEntry component | ||||||||
Wave 02: Render ChatLog component */} | ||||||||
</main> | ||||||||
</div> | ||||||||
); | ||||||||
// const [likesCount, setLikesCount] = useState(0); | ||||||||
const [entries, setEntries] = useState(chatMessages); | ||||||||
|
||||||||
const sumHearts = () => { | ||||||||
let total = 0; | ||||||||
|
||||||||
entries.forEach((entry) => { | ||||||||
if (entry.liked) { | ||||||||
total++; | ||||||||
} | ||||||||
}); | ||||||||
return total; | ||||||||
}; | ||||||||
|
||||||||
const switchHeart = (updatedEntry) => { | ||||||||
const updatedEntries = entries.map((entry) => { | ||||||||
if (entry.id === updatedEntry.id) { | ||||||||
// entry.liked = !entry.liked; | ||||||||
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.
Suggested change
|
||||||||
|
||||||||
return { ...entry, liked: !entry.liked }; | ||||||||
} | ||||||||
return entry; | ||||||||
}); | ||||||||
setEntries(updatedEntries); | ||||||||
}; | ||||||||
|
||||||||
return ( | ||||||||
<div id="App"> | ||||||||
<header> | ||||||||
<h1>Allie's Chat App</h1> | ||||||||
<section className="black" id="heartWidget"> | ||||||||
{sumHearts()} ❤️s | ||||||||
</section> | ||||||||
</header> | ||||||||
|
||||||||
<main> | ||||||||
{/* Wave 01: Render one ChatEntry component */} | ||||||||
|
||||||||
{/* Wave 02: Render ChatLog component */} | ||||||||
Comment on lines
+44
to
+46
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.
Suggested change
|
||||||||
<ChatLog entries={entries} onUpdateHeart={switchHeart}></ChatLog> | ||||||||
</main> | ||||||||
</div> | ||||||||
); | ||||||||
}; | ||||||||
|
||||||||
export default App; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,22 +1,52 @@ | ||||||||||||||||||||
import React from 'react'; | ||||||||||||||||||||
import './ChatEntry.css'; | ||||||||||||||||||||
import PropTypes from 'prop-types'; | ||||||||||||||||||||
import TimeStamp from './TimeStamp'; | ||||||||||||||||||||
import { useState } from 'react'; | ||||||||||||||||||||
|
||||||||||||||||||||
const ChatEntry = (props) => { | ||||||||||||||||||||
return ( | ||||||||||||||||||||
<div className="chat-entry local"> | ||||||||||||||||||||
<h2 className="entry-name">Replace with name of 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> | ||||||||||||||||||||
</section> | ||||||||||||||||||||
</div> | ||||||||||||||||||||
); | ||||||||||||||||||||
const [likePost, setLikePost] = useState(props.liked); | ||||||||||||||||||||
|
||||||||||||||||||||
const toggleLike = () => { | ||||||||||||||||||||
const updatedEntry = { | ||||||||||||||||||||
id: props.id, | ||||||||||||||||||||
sender: props.sender, | ||||||||||||||||||||
body: props.body, | ||||||||||||||||||||
timeStamp: props.timeStamp, | ||||||||||||||||||||
liked: !props.liked, | ||||||||||||||||||||
}; | ||||||||||||||||||||
setLikePost(!likePost); | ||||||||||||||||||||
Comment on lines
+16
to
+18
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. Looks like we are updating the chat message data from Consider removing lines 8 and 18 completely |
||||||||||||||||||||
props.onUpdate(updatedEntry); | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
const heartState = 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>{props.body}</p> | ||||||||||||||||||||
{/* <p className="entry-time">Replace with TimeStamp component</p> */} | ||||||||||||||||||||
Comment on lines
+26
to
+31
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.
Suggested change
|
||||||||||||||||||||
<p className="entry-time"> | ||||||||||||||||||||
<TimeStamp time={props.timeStamp}></TimeStamp> | ||||||||||||||||||||
</p> | ||||||||||||||||||||
<button onClick={toggleLike} className="like"> | ||||||||||||||||||||
{heartState} | ||||||||||||||||||||
</button> | ||||||||||||||||||||
</section> | ||||||||||||||||||||
</div> | ||||||||||||||||||||
); | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
ChatEntry.propTypes = { | ||||||||||||||||||||
//Fill with correct proptypes | ||||||||||||||||||||
//Fill with correct proptypes | ||||||||||||||||||||
id: PropTypes.number, | ||||||||||||||||||||
sender: PropTypes.string, | ||||||||||||||||||||
body: PropTypes.string, | ||||||||||||||||||||
timeStamp: PropTypes.string, | ||||||||||||||||||||
liked: PropTypes.bool, | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ChatLog = (props) => { | ||
const entries = props.entries; | ||
|
||
const chatComponents = entries.map((message, index) => { | ||
return ( | ||
<div className="chat-log" key={message.id}> | ||
<ChatEntry | ||
id={message.id} | ||
sender={message.sender} | ||
body={message.body} | ||
timeStamp={message.timeStamp} | ||
liked={message.liked} | ||
onUpdate={props.onUpdateHeart} | ||
></ChatEntry> | ||
</div> | ||
); | ||
}); | ||
return chatComponents; | ||
Comment on lines
+9
to
+22
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 works! HTML-wise, it is creating a lot of extra const chatComponents = entries.map((message, index) => {
return (
<ChatEntry
key={message.id}
id={message.id}
sender={message.sender}
body={message.body}
timeStamp={message.timeStamp}
liked={message.liked}
onUpdate={props.onUpdateHeart}
/>
);
});
return (
<div className="chat-log">
{chatComponents}
</div>
); Now there is only one |
||
}; | ||
|
||
ChatLog.propTypes = { | ||
entries: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.number, | ||
sender: PropTypes.string, | ||
body: PropTypes.string, | ||
timeStamp: PropTypes.string, | ||
liked: PropTypes.bool, | ||
}) | ||
), | ||
onUpdateHeart: PropTypes.func, | ||
}; | ||
|
||
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.
Let's remove this line of code since we aren't using it anymore