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
26 changes: 23 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
import './App.css';
import ChatLog from './components/ChatLog';
import messages from './data/messages.json';
import { useState } from 'react';

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

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

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

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

export default App;
export default App;
31 changes: 21 additions & 10 deletions src/components/ChatEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import PropTypes from 'prop-types';
import './ChatEntry.css';
import TimeStamp from './TimeStamp';

const ChatEntry = () => {
const ChatEntry = (props) => {
return (
// Replace the outer tag name with a semantic element that fits our use case
<replace-with-relevant-semantic-element className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<article className="chat-entry local">
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

All chat entries are hardcoded with the "local" class, which means all messages will appear on the left side with yellow styling. Based on the CSS file which defines both "local" and "remote" styles, the className should be dynamically determined based on which user sent the message. Consider adding logic to differentiate between local and remote messages, possibly by comparing the sender to a current user prop.

Copilot uses AI. Check for mistakes.
<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.onLikeToggle(props.id)}
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

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

The like button is missing an accessible label. Users relying on screen readers won't know what the button does. Add an aria-label attribute such as "like" or "toggle like" to make this button accessible.

Suggested change
onClick={() => props.onLikeToggle(props.id)}
onClick={() => props.onLikeToggle(props.id)}
aria-label={props.liked ? "unlike" : "like"}

Copilot uses AI. Check for mistakes.
>
{props.liked ? '❤️' : '🤍'}
</button>
</section>
</replace-with-relevant-semantic-element>
</article>
);
};

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;
export default ChatEntry;
35 changes: 35 additions & 0 deletions src/components/ChatLog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import PropTypes from 'prop-types';
import ChatEntry from './ChatEntry';

const ChatLog = (props) => {
return (
<section>
{props.entries.map(message => (
<ChatEntry
key={message.id}
id={message.id}
sender={message.sender}
body={message.body}
timeStamp={message.timeStamp}
liked={message.liked}
onLikeToggle={props.onLikeToggle}
/>
))}
</section>
);
};

ChatLog.propTypes = {
entries: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).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;