Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#App {
background-color: #87cefa;
background-color: #E6E6FA;
}

#App header {
Expand Down
43 changes: 39 additions & 4 deletions src/App.js
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';

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.

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

Choose a reason for hiding this comment

The 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>

Choose a reason for hiding this comment

The 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>
);
Expand Down
40 changes: 34 additions & 6 deletions src/components/ChatEntry.js
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using ... to make this more concise

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the isRequired!

};

export default ChatEntry;
4 changes: 4 additions & 0 deletions src/components/ChatLog.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
margin: auto;
max-width: 50rem;
}

.chat-log ul{
list-style: none;
}
37 changes: 37 additions & 0 deletions src/components/ChatLog.js
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using arrayOf to make the prop types more explicit.

onToggleLike: PropTypes.func,
};

export default ChatLog;