diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..62a6c626a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,17 +1,34 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import { useState } from 'react'; +import messages from './data/messages.json'; const App = () => { + const [chatMessages, setChatMessages] = useState(messages); + + const toggleLike = (id) => { + const updatedMessages = chatMessages.map((message) => { + if (message.id === id) { + // message.liked = !message.liked; + return {...message, liked:!message.liked}; + } else { + return message; + } + }); + setChatMessages(updatedMessages); + }; + + const totalLikes = chatMessages.filter((message) => message.liked).length; + return (
-

Application title

+

Vladmir and Estragon

+

{totalLikes} ❤️s

-
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} -
+
); }; -export default App; +export default App; \ No newline at end of file diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..ce121ab26 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,35 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; + +const ChatEntry = (props) => { + const handleLikeClick = () => { + props.onLike(props.id); // Notify the parent component (App) to toggle like state + }; -const ChatEntry = () => { return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+ +

+
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: PropTypes.string, + id: PropTypes.number, + body: PropTypes.string, + timeStamp: PropTypes.string, + liked: PropTypes.bool, + onLike: PropTypes.func, // Ensure the `onLike` prop is passed }; -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..217936a67 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,35 @@ +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const chatEntries = props.entries.map((entry) => { + return ( + + ); + }); + + return
{chatEntries}
; +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + sender: PropTypes.string, + id: PropTypes.number, + body: PropTypes.string, + timeStamp: PropTypes.string, + liked: PropTypes.bool, + }) + ).isRequired, + onLike: PropTypes.func.isRequired, +}; + +export default ChatLog; \ No newline at end of file