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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"luxon": "^2.5.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-icons": "^5.5.0"
},
"devDependencies": {
"@eslint/compat": "^1.2.0",
Expand Down
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

#App header section {
background-color: #e0ffff;
font-size: 1.2em;
color: #222;
font-weight: bold;
padding: 1%;
}

#App .widget {
Expand Down
29 changes: 24 additions & 5 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import { useState } from 'react';
import './App.css';
import ChatLog from './components/ChatLog';
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">
<div id='App'>
<header>
<h1>Application title</h1>
<h1>Chat Between Vladimir and Estragon</h1>
<section>{totalLikes} ❤️s</section>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<div>
<ChatLog
entries={entries}
onLikeToggle={toggleLike}
/>
</div>
</main>
</div>
);
};

export default App;
export default App;
24 changes: 17 additions & 7 deletions src/components/ChatEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import './ChatEntry.css';
import TimeStamp from './TimeStamp';
import PropTypes from 'prop-types';

const ChatEntry = () => {
const ChatEntry = (props) => {
const side = props.sender === 'Vladimir' ? 'local' : 'remote';
return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<div className={`chat-entry ${side}`}>
<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>
<TimeStamp time={props.timeStamp}/>
<button className="like" onClick={() => props.onLikeToggle(props.id)}>
{props.liked ? '❤️' : '🤍'}
</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;
30 changes: 30 additions & 0 deletions src/components/ChatLog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import './ChatLog.css';
import ChatEntry from './ChatEntry';
import PropTypes from 'prop-types';

const ChatLog = ({ entries, onLikeToggle }) => {
return (
<div className='chat-log'>
<ul>
{entries.map((entry) => (
<ChatEntry {...entry} onLikeToggle={onLikeToggle} key={entry.id} />
))}
</ul>
</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;
4 changes: 2 additions & 2 deletions src/data/messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{
[
{
"id": 1,
"sender":"Vladimir",
"body":"why are you arguing with me",
Expand Down