-
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
Tigers-Samiya-Chatlog #126
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,15 +1,35 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import './App.css'; | ||
import chatMessages from './data/messages.json'; | ||
// import ChatEntry from './components/ChatEntry'; | ||
import ChatLog from './components/ChatLog'; | ||
|
||
//<ChatEntry | ||
//sender={chatMessages[0].sender} | ||
//body={chatMessages[0].body} | ||
//timeStamp={chatMessages[0].timeStamp} | ||
///> | ||
const App = () => { | ||
const[likesCount,setLikeCount]=useState(0); | ||
const updateLikes=(isLike)=>{ | ||
if (isLike){ | ||
setLikeCount(likesCount+1); | ||
} else { | ||
setLikeCount(likesCount-1) | ||
|
||
} | ||
} | ||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Chat between Vladmir and Estragon</h1> | ||
<h2>{likesCount}🤍s</h2> | ||
<h3>ChatLog</h3> | ||
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
<ChatLog entries={chatMessages}updateLikes={updateLikes} | ||
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. Well done passing parameters via props! |
||
/> | ||
{/* Chatlog | ||
Wave 02: Render ChatLog component */} | ||
</main> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,52 @@ | ||
import React from 'react'; | ||
//import React, { useState } from 'react'; | ||
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
import {useState} from 'react'; | ||
|
||
|
||
const ChatEntry = (props) => { | ||
const[likeButton,setLikeButton]=useState('🤍'); | ||
const clickedToggle=()=>{ | ||
|
||
if(likeButton==='🤍'){ | ||
setLikeButton('❤️') | ||
props.updateLikes(true) | ||
}else{ | ||
setLikeButton('🤍') | ||
props.updateLikes(false) | ||
} | ||
} | ||
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. Here is where you could have used the state that you pass in to handle what your output is. For example, if we had a props parameter called "isLiked," we could have used that in a simple ternary operator to spit out either the liked heart or the unliked heart. |
||
|
||
|
||
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> | ||
<h2 className="entry-name">{props.sender}</h2> | ||
<section className="entry-bubble">{props.body} | ||
<p></p> | ||
<p className="entry-time"> | ||
<TimeStamp time={props.timeStamp}/> | ||
</p> | ||
<button className="like" onClick={clickedToggle}>{likeButton}</button> | ||
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. emember that we have passed down a function that is supposed to handle this for us. If we are having to rewrite this function, we aren't effectively lifting state up. |
||
|
||
</section> | ||
</div> | ||
); | ||
}; | ||
//eventhandler (on click)==== | ||
//for | ||
// const likeTotal(props)=> | ||
//setlikeCount,Likecount) | ||
// | ||
|
||
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
id:PropTypes.number.isRequired, | ||
sender:PropTypes.string.isRequired, | ||
body:PropTypes.string.isRequired, | ||
timeStamp:PropTypes.string.isRequired, | ||
likes: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. Great use of proptypes here! |
||
//`ChatEntry` with props `sender`, `body`, and `timeStamp`. | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ChatEntry from './ChatEntry'; | ||
import './ChatLog.css'; | ||
|
||
|
||
|
||
const ChatLog=(props)=>{ | ||
const entries =props.entries; | ||
return( | ||
<ul className='chat-log'> | ||
{entries.map((entry,id)=>( | ||
<ChatEntry | ||
key={entry.id} | ||
id={entry.id} | ||
sender={entry.sender} | ||
body={entry.body} | ||
timeStamp={entry.timeStamp} | ||
updateLikes={props.updateLikes} | ||
liked={entry.liked} | ||
|
||
></ChatEntry> | ||
))} | ||
</ul> | ||
|
||
); | ||
}; | ||
|
||
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. Missing our proptypes! Other than that, this component is well-written! |
||
|
||
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.
This is a good start. However, your program is only changing the state of the likesCount and doesn't ever address the chatMessages. When you change the buttons, the likes will change visually, but each message's backend data will remain unchanged.