-
Notifications
You must be signed in to change notification settings - Fork 111
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
Seattle Otters - Joanna #108
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,21 +2,58 @@ import React from 'react'; | |||||
import './ChatEntry.css'; | ||||||
import PropTypes from 'prop-types'; | ||||||
|
||||||
const convertMsToDays = (ms) => { | ||||||
const days = ms / 1000 / 60 / 60 / 24; | ||||||
return Math.round(days); | ||||||
}; | ||||||
|
||||||
const timeStampMessage = (days) => { | ||||||
let msgStamp = 'unable to get timestamp'; | ||||||
if (days < 1) { | ||||||
msgStamp = 'Today'; | ||||||
} else if (days >= 1 && days < 365) { | ||||||
msgStamp = 'Today'; | ||||||
} else if (days >= 365) { | ||||||
const yrs = Math.floor(days / 365); | ||||||
msgStamp = `${yrs} years ago`; | ||||||
} | ||||||
return msgStamp; | ||||||
} | ||||||
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. I can see that you put a lot of work into this section, but just so you're aware, the Timestamp component that was provided with the project will do all of this work for you and render the correct relative time. It takes the timeStamp from the message data as a prop. |
||||||
|
||||||
const ChatEntry = (props) => { | ||||||
const msgTime = new Date(props.timeStamp); | ||||||
const today = new Date(); | ||||||
const daysSinceMsg = convertMsToDays(today-msgTime); | ||||||
|
||||||
const toggleLiked= props.likedCallback; | ||||||
|
||||||
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> | ||||||
<p>{props.body}</p> | ||||||
<p className="entry-time"> | ||||||
{daysSinceMsg < 1 | ||||||
? msgTime.toLocaleTimeString([], { | ||||||
hour: '2-digit', | ||||||
minute: '2-digit', | ||||||
}) | ||||||
: timeStampMessage(daysSinceMsg)} | ||||||
</p> | ||||||
<button className="like">🤍</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. Removing this line causes all tests to pass.
Suggested change
|
||||||
<button className="like" onClick={() => toggleLiked(props.id)}> | ||||||
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. 💯 |
||||||
{`${props.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. This can be written slightly simpler:
Suggested change
Strings inside of |
||||||
</button> | ||||||
</section> | ||||||
</div> | ||||||
); | ||||||
}; | ||||||
|
||||||
ChatEntry.propTypes = { | ||||||
//Fill with correct proptypes | ||||||
|
||||||
ChatEntry.propTypes = { | ||||||
sender: PropTypes.string.isRequired, | ||||||
body: PropTypes.string.isRequired, | ||||||
timeStamp: PropTypes.string.isRequired, | ||||||
likedCallback: PropTypes.func.isRequired, | ||||||
}; | ||||||
|
||||||
export default ChatEntry; | ||||||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import './ChatLog.css'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ChatLog = (props) => { | ||
const entries = props.entries; | ||
console.log(entries); | ||
|
||
const entryLog = entries.map((entry) => { | ||
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. 👍 |
||
return ( | ||
<ChatEntry | ||
key={entry.id ? entry.id : `${entry.sender}_${entry.timeStamp}`} | ||
id={entry.id} | ||
sender={entry.sender} | ||
body={entry.body} | ||
timeStamp={entry.timeStamp} | ||
liked={entry.liked} | ||
likedCallback={props.likedCallback} | ||
></ChatEntry> | ||
); | ||
}); | ||
return <div className ="chat-log">{entryLog}</div>; | ||
}; | ||
ChatLog.propTypes = { | ||
entries: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
}) | ||
), | ||
likedCallback: 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.
Great callback function!