-
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
Lions - Ivy S #120
base: main
Are you sure you want to change the base?
Lions - Ivy S #120
Changes from all commits
0856953
5b30866
727589a
23744d7
314616c
872729d
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,5 +1,5 @@ | ||
#App { | ||
background-color: #87cefa; | ||
background-color: #E6E6FA; | ||
} | ||
|
||
#App header { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,51 @@ | ||
import React from 'react'; | ||
import './App.css'; | ||
// import ChatEntry from './components/ChatEntry'; | ||
import ChatLog from './components/ChatLog'; | ||
import chatMessages from './data/messages.json'; | ||
import { useState } from 'react'; | ||
|
||
const App = () => { | ||
const [entries, setEntries] = useState(chatMessages) | ||
|
||
const updateMessages = (updatedMessage) => { | ||
const messages = entries.map(message => { | ||
if (message.id === updatedMessage.id) { | ||
return updatedMessage; | ||
} | ||
else { | ||
return message | ||
} | ||
Comment on lines
+13
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. Small nitpick: the else is not needed here. |
||
}); | ||
setEntries(messages); | ||
}; | ||
|
||
const totalLikes = (entries) => { | ||
let likes = 0 | ||
for (let message of entries){ | ||
if (message.liked === true){ | ||
likes +=1; | ||
} | ||
} | ||
return `${likes} ❤️s`; | ||
}; | ||
|
||
return ( | ||
<div id="App"> | ||
<header> | ||
<h1>Application title</h1> | ||
</header> | ||
<h1>Heard it Through The Ivy Vine</h1> | ||
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. 😂 |
||
<section> | ||
<div className='widget'> | ||
<div id='heartWidget'>{totalLikes(entries)}</div> | ||
</div> | ||
</section> | ||
</header> | ||
|
||
<main> | ||
{/* Wave 01: Render one ChatEntry component | ||
Wave 02: Render ChatLog component */} | ||
<ChatLog | ||
entries={entries} | ||
onToggleLike={updateMessages} | ||
></ChatLog> | ||
</main> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,50 @@ | ||
import React from 'react'; | ||
import './ChatEntry.css'; | ||
import PropTypes from 'prop-types'; | ||
import TimeStamp from './TimeStamp'; | ||
|
||
const ChatEntry = (props) => { | ||
let isLocal = 'local'; | ||
if (props.sender !== 'Vladimir'){ | ||
isLocal = 'remote'; | ||
} | ||
|
||
const toggleLike = () => { | ||
const updatedMessage = { | ||
sender: props.sender, | ||
id: props.id, | ||
body: props.body, | ||
timeStamp: props.timeStamp, | ||
liked: !props.liked, | ||
}; | ||
Comment on lines
+13
to
+19
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. Consider using |
||
props.onToggleLike(updatedMessage); | ||
} | ||
|
||
|
||
const heart = props.liked ? '❤️' : '🤍'; | ||
|
||
return ( | ||
<div className="chat-entry local"> | ||
<h2 className="entry-name">Replace with name of sender</h2> | ||
<div className={`chat-entry ${isLocal}`}> | ||
<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"> | ||
<TimeStamp time={props.timeStamp}></TimeStamp> | ||
</p> | ||
<button onClick={toggleLike} className="like">{heart}</button> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
|
||
ChatEntry.propTypes = { | ||
//Fill with correct proptypes | ||
id: PropTypes.number, | ||
sender: PropTypes.string.isRequired, | ||
body: PropTypes.string.isRequired, | ||
timeStamp: PropTypes.string.isRequired, | ||
liked: PropTypes.bool, | ||
onToggleLike : PropTypes.func, | ||
Comment on lines
+46
to
+47
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. Don't forget the |
||
}; | ||
|
||
export default ChatEntry; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
margin: auto; | ||
max-width: 50rem; | ||
} | ||
|
||
.chat-log ul{ | ||
list-style: none; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import './ChatLog.css'; | ||
import ChatEntry from './ChatEntry'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ChatLog = (props) => { | ||
const entryComponants = props.entries.map((message, index) => { | ||
return( | ||
<li key={index}> | ||
<ChatEntry | ||
id = {message.id} | ||
sender={message.sender} | ||
body={message.body} | ||
liked = {message.liked} | ||
timeStamp={message.timeStamp} | ||
onToggleLike = {props.onToggleLike} | ||
></ChatEntry> | ||
</li> | ||
); | ||
}); | ||
|
||
return ( | ||
<section className="chat-log"> | ||
<ul> | ||
{entryComponants} | ||
</ul> | ||
</section> | ||
|
||
); | ||
}; | ||
|
||
ChatLog.propTypes = { | ||
entries: PropTypes.array.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. Consider using |
||
onToggleLike: 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.
Remember to remove unneeded comments.