diff --git a/src/App.css b/src/App.css index d97beb4e..df3fe911 100644 --- a/src/App.css +++ b/src/App.css @@ -1,3 +1,4 @@ +/* src/App.css */ #App { background-color: #87cefa; } diff --git a/src/App.js b/src/App.js index c1085909..979e1a82 100644 --- a/src/App.js +++ b/src/App.js @@ -1,19 +1,33 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; const App = () => { + + const [totalLikes, setTotalLikes] = useState(0); + + const handleLikeChange = (isLiked) => { + // Increment or decrement based on the liked status + setTotalLikes(prevTotalLikes => isLiked ? prevTotalLikes + 1 : prevTotalLikes - 1); + } + return (
-

Application title

+

Chat Log

+

{totalLikes} ❤️s

{/* Moved the total likes display to the top */}
+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
+
); -}; +} export default App; diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa4..94df4123 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -1,3 +1,4 @@ +/* src/components/ChatEntry.css */ button { background: none; color: inherit; diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b..82909f25 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,41 @@ -import React from 'react'; -import './ChatEntry.css'; + +import React, { useState } from 'react'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; +import './ChatEntry.css'; const ChatEntry = (props) => { + const [liked, setLiked] = useState(props.liked); + + const toggleLiked = () => { + const newLikedStatus = !liked; + setLiked(newLikedStatus); + + // Safeguard the invocation of onLike + if (props.onLike) { + props.onLike(newLikedStatus); + } + }; + return ( -
-

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, + // Make onLike prop optional + onLike: PropTypes.func }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1..f68c07ba 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -1,3 +1,4 @@ +/* src/components/ChatLog.css */ .chat-log { margin: auto; max-width: 50rem; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..0118f992 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,23 @@ +// src/components/ChatLog.js +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = (props) => { + +const chatEntries = props.entries.map(entry => ( + +)); + +return ( +
+ {chatEntries} +
+); +} + +export default ChatLog; diff --git a/src/components/TimeStamp.js b/src/components/TimeStamp.js index e8892b4d..6b19fc18 100644 --- a/src/components/TimeStamp.js +++ b/src/components/TimeStamp.js @@ -1,3 +1,4 @@ +// src/components/TimeStamp.js import { DateTime } from 'luxon'; import PropTypes from 'prop-types';