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
6 changes: 4 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
font-size:0.8em;
padding-left: 1em;
padding-right: 1em;
padding-top: 0.5em;
padding-bottom: 0.5em;
}

#App #heartWidget {
font-size: 1.5em;
margin: 1em
font-size: 1em;
margin: 1em;
}

#App span {
Expand Down
22 changes: 19 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { useState } from 'react';
import ChatLog from './components/ChatLog';
import messages from './data/messages.json';
import './App.css';

const App = () => {
const [chatData, setChatData] = useState(messages);

const toggleLike = (id) => {
setChatData(chatData.map((message) => {
if (message.id === id) {
return { ...message, liked: !message.liked };
}
return message;
}));
};

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Camille's Chatroom</h1>
<section className="widget" id="heartWidget">
{chatData.filter((entry) => entry.liked).length} ❤️s
</section>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
Wave 02: Render ChatLog component */}
<ChatLog entries={chatData} onLike={toggleLike} />
</main>
</div>
);
Expand Down
25 changes: 19 additions & 6 deletions src/components/ChatEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp'
import './ChatEntry.css';

const ChatEntry = () => {
const ChatEntry = (props) => {
const heartColor = props.liked ? '❤️' : '🤍';

return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<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.onLike(props.id)}>
{heartColor}
</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,
onLike: PropTypes.func.isRequired,
};

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

const ChatLog = (props) => {
const chatEntries = props.entries.map((entry) => {
return (
<ChatEntry
key={entry.id}
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
liked={entry.liked}
onLike={props.onLike}
/>
);
});

return (
<div className="chat-log">
{chatEntries}
</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,
onLike: PropTypes.func.isRequired,
};

export default ChatLog;