-
Notifications
You must be signed in to change notification settings - Fork 111
Sea Turtles/ Theresa Davis #100
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
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 |
|---|---|---|
| @@ -1,19 +1,54 @@ | ||
| import React from 'react'; | ||
| import './App.css'; | ||
| import ChatLog from './components/ChatLog' | ||
| import chatMessages from './data/messages.json'; | ||
| import {useState} from 'react'; | ||
| // import ChatEntry from './components/ChatEntry' | ||
|
|
||
| const App = () => { | ||
| return ( | ||
| <div id="App"> | ||
|
|
||
| console.log(chatMessages); | ||
|
|
||
| function App () { | ||
|
|
||
| const [chatData, setChatData] = useState(chatMessages) | ||
| const updateChatData = updatedChat => { | ||
|
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 function looks good. You can remove the console log on line 15 |
||
| console.log({updatedChat}) | ||
| const chats = chatData.map(chat => { | ||
| if(chat.id === updatedChat.id){ | ||
|
|
||
| return updatedChat; | ||
| } else{ | ||
| return chat; | ||
| } | ||
| }); | ||
| setChatData(chats); | ||
| }; | ||
|
|
||
| const calcTotalHearts = ()=>{ | ||
|
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 way to use existing data to calculate total likes. You could also use reduce like |
||
| let total = 0; | ||
| for (let x of chatData){ | ||
| if(x.liked === true){ | ||
| total += 1; | ||
| } }; | ||
| return total | ||
| } | ||
|
|
||
| return( | ||
| <div id = "App"> | ||
| <header> | ||
| <h1>Application title</h1> | ||
| <h1>Chat Log Between Vladimir and Estragon</h1> | ||
| <h3> Likes 💜</h3> | ||
| <h3> {calcTotalHearts()} </h3> | ||
| </header> | ||
| <main> | ||
| {/* Wave 01: Render one ChatEntry component | ||
| Wave 02: Render ChatLog component */} | ||
| <ChatLog | ||
| chats={chatData} | ||
| onUpdateChat={updateChatData} | ||
| /> | ||
| </main> | ||
| </div> | ||
| ); | ||
| }; | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| export default App; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,38 @@ | ||
| import React from 'react'; | ||
| import './ChatEntry.css'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
|
|
||
| const ChatEntry = (props) => { | ||
| const onButtonClick = (id) => { | ||
| console.log('onButtonClick') | ||
| const updatedChat = { | ||
| id: props.id, | ||
| sender: props.sender, | ||
| body: props.body, | ||
| liked: !props.liked, | ||
| likeCount: props.likeCount | ||
| }; | ||
| props.onUpdateChat(updatedChat); | ||
| }; | ||
| const displayLikes = props.liked ? '💜' : '🤍'; | ||
|
|
||
| return ( | ||
| <div className="chat-entry local"> | ||
| <h2 className="entry-name">Replace with name of sender</h2> | ||
| <h5>{props.likeCount}</h5> | ||
| <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">{props.timeStamp}</p> | ||
|
|
||
| <button onClick= {() => onButtonClick(props.id)} className="like"> | ||
| {displayLikes} | ||
| </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. you don't have any prop types. Your test should be looking for prop types for sender, body and timeStamp |
||
| //Fill with correct proptypes | ||
| }; | ||
|
|
||
| export default ChatEntry; | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||
| import React from 'react'; | ||||||
| import './ChatLog.css'; | ||||||
| import ChatEntry from './ChatEntry'; | ||||||
| import PropTypes from 'prop-types'; | ||||||
|
|
||||||
|
|
||||||
| const ChatLog = (props) => { | ||||||
|
|
||||||
| const chatDataMap = props.chats.map(item =>( | ||||||
|
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. using const chatDataMap = props.chats.map((item, i) =>
<ChatEntry
key={i} |
||||||
| <ChatEntry | ||||||
| key={item.id} | ||||||
| id={item.id} | ||||||
| sender={item.sender} | ||||||
| body={item.body} | ||||||
| timeStamp={item.timeStamp} | ||||||
| liked={item.liked} | ||||||
| onUpdateChat={props.onUpdateChat}/> )) | ||||||
|
|
||||||
| return ( | ||||||
| <main> | ||||||
| {chatDataMap} | ||||||
| {/* Wave 01: Render one ChatEntry component | ||||||
| Wave 02: Render ChatLog component */} | ||||||
|
Comment on lines
+22
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.
Suggested change
|
||||||
| </main> | ||||||
|
|
||||||
| ); } | ||||||
|
|
||||||
| ChatLog.propTypes = { | ||||||
| chats:PropTypes.arrayOf(PropTypes.shape({ | ||||||
|
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 use of shape. Make sure to only had isRequired to props that are a must for the component to render. If you want them all to be required then you should update the tests to reflect that. |
||||||
| id: PropTypes.number.isRequired, | ||||||
| sender: PropTypes.string.isRequired, | ||||||
| body: PropTypes.string.isRequired, | ||||||
| liked: PropTypes.bool.isRequired, | ||||||
| timeStamp: PropTypes.string.isRequired | ||||||
|
|
||||||
| })), | ||||||
| onUpdateChat: 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 this console log after debugging