diff --git a/src/App.css b/src/App.css index d97beb4e6..df3fe9118 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 c10859093..979e1a821 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 05c3baa44..94df4123c 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 b92f0b7b2..82909f258 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 378848d1f..f68c07ba6 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 000000000..0118f992e --- /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 e8892b4d4..6b19fc189 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';