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
36 changes: 33 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import './App.css';
import ChatEntry from './components/ChatEntry';
import ChatLog from './components/Chatlog';
import chatData from './data/messages.json';
import React, { useState } from 'react';


// const Chat = {
// id: 1,
// sender:'Vladimir',
// body:'why are you arguing with me',
// timeStamp:'2018-05-29T22:49:06+00:00',
// liked: false
// };

const App = () => {
const [entries, setEntries] = useState(chatData);

const toggleLike = (id) => {
const updatedEntries = entries.map((entry) =>
entry.id === id ? { ...entry, liked: !entry.liked } : entry
);
setEntries(updatedEntries);
};

const totalLikes = entries.filter((entry) => entry.liked).length;

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Ellie Chat Log</h1>
<h2>{totalLikes} ❤️s</h2>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
{/* Wave 01: Render one ChatEntry component */}
{/* <ChatEntry entries={Chat} /> */}
{/* Wave 02: Render ChatLog component */}
<ChatLog
entries={chatData}
onLikeToggle={toggleLike}
/>
</main>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/ChatEntry.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,9 @@ button {

.chat-entry.remote .entry-bubble:hover::before {
background-color: #a9f6f6;
}

button.like {
font-size: 1.5rem;
margin-top: 0.5rem;
}
27 changes: 21 additions & 6 deletions src/components/ChatEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
// components/ChatEntry.js
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';

const ChatEntry = ({ id, sender, body, timeStamp, liked, onLikeToggle }) => {
const heart = liked ? '❤️' : '🤍';


const ChatEntry = () => {
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 className="like" onClick={() => onLikeToggle(id)}>
{heart}
</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,
onLikeToggle: PropTypes.func.isRequired,
};

export default ChatEntry;
12 changes: 7 additions & 5 deletions src/components/ChatEntry.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ describe('Wave 01: ChatEntry', () => {
beforeEach(() => {
render(
<ChatEntry
id={7}
sender="Joe Biden"
body="Get out by 8am. I'll count the silverware"
timeStamp="2018-05-18T22:12:03Z"
liked={false}
entries={{
id:7,
sender:'Joe Biden',
body:'Get out by 8am. I \'ll count the silverware',
timeStamp: '2018-05-18T22:12:03Z',
liked: false,
}}
/>
);
});
Expand Down
37 changes: 37 additions & 0 deletions src/components/Chatlog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// components/ChatLog.js
import './Chatlog.css';
import PropTypes from 'prop-types';
import ChatEntry from './ChatEntry';

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

ChatLog.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,
})
).isRequired,
onLikeToggle: PropTypes.func.isRequired,
};

export default ChatLog;
2 changes: 1 addition & 1 deletion src/components/TimeStamp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ TimeStamp.propTypes = {
time: PropTypes.string.isRequired,
};

export default TimeStamp;
export default TimeStamp;