-
Notifications
You must be signed in to change notification settings - Fork 153
Final version #132
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?
Final version #132
Changes from all commits
1ae791d
24e3c0a
b667381
a429e5e
e3342b4
50f4576
9de32fc
6aeee59
0d433ec
aac0476
bd61044
c1a36a7
cac7762
621aa91
a4aa3c0
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,39 @@ | ||
import React from 'react'; | ||
import './App.css'; | ||
import { useState } from 'react'; | ||
import chatMessages from './data/messages.json'; | ||
import ChatLog from './components/Chatlog'; | ||
|
||
const App = () => { | ||
const [chatJson, setchatJson] = useState(chatMessages); | ||
|
||
const updatechatJson = (id) => { | ||
const updatedChat = chatJson.map((chat) => { | ||
if (chat.id === id) { | ||
return { ...chat, liked: !chat.liked }; | ||
} else { | ||
return chat; | ||
} | ||
}); | ||
setchatJson(updatedChat); | ||
}; | ||
|
||
const Hearts = () => { | ||
return chatJson.reduce((total, message) => { | ||
return message.liked ? total + 1 : total; | ||
}, 0); | ||
}; | ||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
<h1>Human & Robot</h1> | ||
<h2 className="like">LikeCount: {Hearts()} ❤️</h2> | ||
</header> | ||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog entries={chatJson} setchatJson={updatechatJson}></ChatLog> | ||
</main> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,36 @@ import React from 'react'; | |
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const filledHeart = '❤️'; | ||
const emptyHeart = '🤍'; | ||
|
||
const ChatEntry = (props) => { | ||
const heartOrNot = props.liked ? filledHeart : emptyHeart; | ||
const className = props.sender === 'Estragon' ? 'remote' : 'local'; | ||
|
||
const handleClick = (id) => { | ||
props.handleLike(id); | ||
}; | ||
return ( | ||
<div className="chat-entry local"> | ||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<div className={`chat-entry ${className}`}> | ||
<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> | ||
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's where you'd use the provided |
||
<button className="like" onClick={() => handleClick(props.id)}> | ||
{heartOrNot} | ||
</button> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
id: PropTypes.number.isRequired, | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ChatEntry from './ChatEntry'; | ||
import './ChatLog.css'; | ||
|
||
const ChatLog = (props) => { | ||
const jsonMessages = props.entries.map((messages) => { | ||
return ( | ||
<ChatEntry | ||
id={messages.id} | ||
sender={messages.sender} | ||
body={messages.body} | ||
timeStamp={messages.timeStamp} | ||
liked={messages.liked} | ||
key={messages.key} | ||
handleLike={props.setchatJson} | ||
></ChatEntry> | ||
); | ||
}); | ||
return <div className="chat-log">{jsonMessages}</div>; | ||
}; | ||
|
||
ChatEntry.propTypes = { | ||
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, | ||
key: PropTypes.number.isRequired, | ||
}) | ||
), | ||
}; | ||
|
||
export default ChatLog; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import React from 'react'; | ||
import { DateTime } from 'luxon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const TimeStamp = (props) => { | ||
const timeStamp = (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. No need to have modified this component. Also, React components by convention use capital letters as their names, so |
||
const time = DateTime.fromISO(props.time); | ||
const absolute = time.toFormat('MMMM Do YYYY, h:mm:ss a'); | ||
const relative = time.toRelative(); | ||
|
||
return <span title={absolute}>{relative}</span>; | ||
}; | ||
|
||
export default TimeStamp; | ||
timeStamp.propTypes = { | ||
timeStampmessage: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
messageContent: PropTypes.number, | ||
}) | ||
), | ||
}; | ||
export default timeStamp; |
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.
The tests were expecting this text to read "3 ❤️s", which is why you saw those tests fail.