diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..3d63a904f 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,33 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import data from '/src/data/messages.json'; +import { useState } from 'react'; + const App = () => { + + const [entries, setEntries] = useState(data) + + function toggleLike(id) { + const updatedEntries = entries.map(entry => { + if (entry.id === id) { + return { ...entry, liked: !entry.liked } + } + return entry; + }); + setEntries(updatedEntries); + }; + + const totalLikes = entries.filter(entry => entry.liked).length; + return (
-

Application title

+

Chat Between Vladimir and Estragon

+

{totalLikes} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..7e592ffbd 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,31 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; +import propTypes from 'prop-types'; -const ChatEntry = () => { +const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLike }) => { + + const localOrRemote = sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote'; + return ( -
-

Replace with name of sender

+
+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{body}

+

+ +

+
); }; ChatEntry.propTypes = { - // Fill with correct proptypes + sender: propTypes.string.isRequired, + body: propTypes.string.isRequired, + timeStamp: propTypes.string.isRequired, + liked: propTypes.bool.isRequired, + onToggleLike: propTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..da3bd0698 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,23 @@ +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ({ entries, onToggleLike }) => { + const chatEntries = entries.map(entry => ( + + )); + + return ( +
{chatEntries}
+ ) + +}; + +export default ChatLog; \ No newline at end of file