diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..b0d2c7d5d 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,17 +1,44 @@ +import React, { useState } from 'react'; import './App.css'; +import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; +import chatMessages from './data/messages.json'; const App = () => { + // const [entries, setEntries] = useState(chatMessages); + const [entries, setEntries] = useState( + chatMessages.map((msg) => ({ ...msg, liked: msg.liked ?? false })) +); + + const 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; + const localSender = "Vladimir"; + return (
-

Application title

+

Chat Log

+

{totalLikes} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); }; + export default App; + + + diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..c85a1920b 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,26 @@ +import TimeStamp from './TimeStamp'; import './ChatEntry.css'; -const ChatEntry = () => { - return ( -
-

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- -
-
- ); +const ChatEntry = ({ id, sender, body, timeStamp, liked, onToggleLike, isLocal }) => { + const heart = liked ? '❤️' : '🤍'; + const entryClass = isLocal ? 'chat-entry local' : 'chat-entry remote'; +return ( +
+

{sender}

+
+

{body}

+

+ {/* +
+
+); }; -ChatEntry.propTypes = { - // Fill with correct proptypes -}; - -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..07f9f885b --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,23 @@ +import ChatEntry from './ChatEntry'; +import './ChatLog.css'; + +const ChatLog = ({ entries, onToggleLike, localSender }) => { + return ( +
+ {entries.map((entry) => ( + + ))} +
+ ); +}; + +export default ChatLog; \ No newline at end of file