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

Anees Quateja (Phoenix) #27

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
720 changes: 650 additions & 70 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.2",
"@vitest/coverage-v8": "^2.1.8",
"eslint": "^9.12.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^5.0.0",
10 changes: 9 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
@@ -71,4 +71,12 @@

.purple {
color: purple
}
}

.like {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
}

23 changes: 20 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import './App.css';
import ChatLog from './components/ChatLog';
// import ChatEntry from './components/ChatEntry';
import React, {useState} from 'react';
import messages from './data/messages.json';


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

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>ChatLog App</h1>
<h2>{totalLikes} ❤️s</h2>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog
entries={entries} onToggleLike={toggleLike}/>
</main>
</div>
);
26 changes: 20 additions & 6 deletions src/components/ChatEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@

import './ChatEntry.css';
import TimeStamp from './TimeStamp'; // TimeStamp is a separate component
import PropTypes from 'prop-types';
// import App from '../App';
import React from 'react';

const ChatEntry = ({id, sender, body, timeStamp, liked, onToggleLike}) => {
const heartEmoji = 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={() => onToggleLike(id)}>
{heartEmoji}
</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,
onToggleLike: PropTypes.func,
};

export default ChatEntry;
38 changes: 38 additions & 0 deletions src/components/ChatLog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import './ChatLog.css';
import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types';
import React from 'react';

const ChatLog = ({entries, onToggleLike}) => {
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}
onToggleLike={onToggleLike}
/>
))}
</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,
onToggleLike: PropTypes.func,
};

export default ChatLog;