Skip to content
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: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
line-height: 0.5em;
border-radius: 10px;
color: black;
font-size:0.8em;
font-size: 0.8em;
padding-left: 1em;
padding-right: 1em;
}
Expand Down
33 changes: 29 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
import React from 'react';
import { React, useState } from 'react';
import './App.css';
import ChatEntry from './components/ChatEntry';
import chatMessages from './data/messages.json';

import ChatLog from './components/ChatLog'
const App = () => {

Choose a reason for hiding this comment

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

👍


const [messageData, setMessageData] = useState(chatMessages)
const [likeData, setLikeData] = useState(0)

const updateMessage = (messageToUpdate) => {
const entries = messageData.map((message) => {
if (message.id === messageToUpdate.id) {
return messageToUpdate
}
Comment on lines +12 to +15
Copy link

@spitsfire spitsfire Jun 28, 2022

Choose a reason for hiding this comment

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

hmm I'm a little confused by this if statement and variable. I don't see you using entries anywhere. Do you need this? It doesn't look like you are updating messageData, only checking to see if messagesToUpdate "exists" in order to add likes.

I think all you need is lines 16-22

else if (messageToUpdate) {
setLikeData(likeData + 1);

} else {
setLikeData(likeData - 1);
};
})
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat Log</h1>
<h2>Like count {likeData} ❤️s</h2>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
{
<ChatLog entries={chatMessages}
onUpdateMessage={updateMessage}>
</ChatLog>

/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
</main>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/components/ChatEntry.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
button {
background: none;
color: inherit;
border: none;
padding: 10px;
font: inherit;
cursor: pointer;
outline: inherit;
color: inherit;
border: none;
padding: 10px;
font: inherit;
cursor: pointer;
outline: inherit;
}

.chat-entry {
Expand Down
43 changes: 37 additions & 6 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
import React from 'react';
import { React, useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';

const ChatEntry = ({ sender, body, liked, timeStamp, id, onUpdateMessage }) => {

Choose a reason for hiding this comment

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

👍

const [isLiked, setIsLiked] = useState(liked);

if (isLiked) {
console.log('is liked');
} else {
console.log('is unliked');
}
Comment on lines +9 to +13

Choose a reason for hiding this comment

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

Don't forget to get rid of debugging comments once you're ready to submit the final submission

Suggested change
if (isLiked) {
console.log('is liked');
} else {
console.log('is unliked');
}


const updateLiked = () => {
console.log('updating heart')

Choose a reason for hiding this comment

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

Suggested change
console.log('updating heart')

setIsLiked(!isLiked);
onUpdateMessage({
sender: sender,
body: body,
timeStamp: timeStamp,
id: id,
Comment on lines +19 to +22

Choose a reason for hiding this comment

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

hmm you are giving this function a lot of editing power when it only needs to update the isLiked property. Think about giving the function access only to isLiked.

isLiked: !isLiked,
})
};

const heartColor = isLiked ? '❤️' : '🤍';

const ChatEntry = (props) => {
return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<h2 className="entry-name">{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>{body}</p>
<p className="entry-time"><TimeStamp time={timeStamp} /></p>

<button onClick={updateLiked} className="like">{heartColor}</button>
</section>
</div>
);
};

ChatEntry.propTypes = {
//Fill with correct proptypes
sender: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
timeStamp: PropTypes.string.isRequired,
id: PropTypes.number.isRequired,
isLiked: PropTypes.bool.isRequired,
onUpdateMessage: PropTypes.func.isRequired

};

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

const ChatLog = ({ entries, id, liked, onUpdateMessage }) => {

Choose a reason for hiding this comment

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

👍


return (
<ul>
{entries.map(chat => {
return (
<ChatEntry
sender={chat.sender}
body={chat.body}
timeStamp={chat.timeStamp}
id={chat.id}
isLiked={chat.liked}
onUpdateMessage={onUpdateMessage}
/>
);
})}
</ul>
);
};

ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
sender: PropTypes.string,
body: PropTypes.string,
timeStamp: PropTypes.string,
id: PropTypes.number.isRequired,
liked: PropTypes.bool.isRequired,
onUpdateMessage: PropTypes.func.isRequire

})
)
}

export default ChatLog;