diff --git a/src/App.css b/src/App.css index d97beb4e6..049854ef8 100644 --- a/src/App.css +++ b/src/App.css @@ -27,7 +27,7 @@ } #App header section { - background-color: #e0ffff; + /* background-color: #e0ffff; */ } #App .widget { diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..29e0eb874 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,37 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import chatMessages from './data/messages.json'; +import { useState } from 'react'; const App = () => { + // Initialize state with the messages + const [messages, setMessages] = useState(chatMessages); + + // Toggle liked state for a message by id + const onLikeToggle = (id) => { + const updatedMessages = messages.map(msg => { + if (msg.id === id) { + return { ...msg, liked: !msg.liked }; + } + return msg; + }); + setMessages(updatedMessages); + }; + + // Calculate total liked count + const likedCount = messages.filter(msg => msg.liked).length; + return (
-

Application title

+

Chat Between Vladimir and Estragon

+
+ {likedCount} ❤️s +
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + {/* Pass the updated messages and toggle handler */} +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..e1ae144f2 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,33 @@ +import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; import './ChatEntry.css'; -const ChatEntry = () => { +const ChatEntry = (props) => { + const { id, sender, body, timeStamp, liked, onLikeToggle } = props; + return ( -
-

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +
+

{sender}

+
+

{body}

+

+ +

+
); }; 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; \ No newline at end of file diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..b1e4ac2ae --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,36 @@ +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; +import './ChatLog.css'; + +const ChatLog = ({ entries, onLikeToggle }) => { + return ( +
+ {entries.map((entry) => ( + + ))} +
+ ); +}; + +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; \ No newline at end of file