diff --git a/project-docs/setup.md b/project-docs/setup.md index f8dbe531..28402514 100644 --- a/project-docs/setup.md +++ b/project-docs/setup.md @@ -1,4 +1,4 @@ -## Baseline + ## Baseline Examine the JSON file located at `src/data/messages.json` to familiarize yourself with the data you will be using. diff --git a/src/App.jsx b/src/App.jsx index 14a7f684..cca53073 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,31 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import MessageData from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [messages, setMessages] = useState(MessageData); + + const toggleLike = (id) => { + setMessages(prevMessages => + prevMessages.map(message => + message.id === id + ? { ...message, liked: !message.liked } + : message + ) + ); + }; + + const totalLikes = messages.filter(message => message.liked).length; + return (
-

Application title

+

Messenger App

+

{totalLikes} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa4..d0e8d653 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -97,4 +97,5 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; -} \ No newline at end of file +} + diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index fe05efa0..f22503f2 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,21 +1,34 @@ import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; + +const ChatEntry = (props) => { -const ChatEntry = () => { return ( - // Replace the outer tag name with a semantic element that fits our use case - -

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +
+
+

{props.sender}

+
+

{props.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.isRequired, + }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 00000000..4ddcf01c --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,22 @@ +import ChatEntry from "./ChatEntry" + +const ChatLog = (props) => { + return ( +
+ {props.entries.map(entry => ( + props.onToggleLike(entry.id)} + /> + ))} +
+ ); +}; + + +export default ChatLog; +