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

Ruby- Mikayla H #68

Open
wants to merge 5 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
36 changes: 33 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
import React from 'react';
import './App.css';
import chatMessages from './data/messages.json';
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.

This import is not needed! It's best practice to remove unused imports before submitting projects.

import ChatLog from './components/ChatLog';
import { useState } from 'react';



//use state
// create func to update likes
//creat func to count likes


const App = () => {

Choose a reason for hiding this comment

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

Excellent!


const [entries, setEntries] = useState(chatMessages);

Choose a reason for hiding this comment

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

Yay, state!


const updateLike = (entryId) => {
const updatedEntries = entries.map((entry) => {
if (entry.id === entryId) {
return { ...entry, liked: !entry.liked };
}
return entry;
});

setEntries(updatedEntries);
}
const newLikedCount = entries.filter(

Choose a reason for hiding this comment

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

Minor note: this line is not indented correctly.

(entry) => entry.liked === true).length;


return (
<div id="App">
<header>
<h1>Application title</h1>
<h1> Mikayla's Application</h1>
<h2>{newLikedCount} ❤️s</h2>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={entries}
updateLike={updateLike} />
</main>
</div>
);
};

export default App;


22 changes: 17 additions & 5 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp'


const ChatEntry = (props) => {

Choose a reason for hiding this comment

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

Excellent!

const changeLike = props.liked ? '❤️' : '🤍';
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>
<button className="like">🤍</button>
<p>{props.body}</p>
<p className="entry-time">
<TimeStamp time = {props.timeStamp}/></p>
<button className="like" onClick={() => {
props.updateLike(props.id)}
}>{changeLike}</button>
</section>
</div>
);
};


ChatEntry.propTypes = {

Choose a reason for hiding this comment

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

Yay, prop types! It would be good to make sure all of the props are here (like id).

//Fill with correct proptypes
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
liked: PropTypes.bool.isRequired,
updateLike: PropTypes.func.isRequired,
};


export default ChatEntry;
39 changes: 39 additions & 0 deletions src/components/ChatLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types'

Choose a reason for hiding this comment

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

This would be a great place to add the ChatLog.css import!



const ChatLog = (props) => {
const {entries, updateLike} = props;
return (
<div className='chat-log'>
{entries.map((entry) => (
<ChatEntry
id={entry.id}
key={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}
updateLike={updateLike}
/>
))}
</div>
);
};
export default ChatLog;


ChatLog.propTypes = {

Choose a reason for hiding this comment

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

Yay, prop types!

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,
})
),

Choose a reason for hiding this comment

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

Remember to add an .isRequired here or else the entries prop is not required!

updateLike: PropTypes.func.isRequired
};