diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..6adcfd7b6 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,14 +1,34 @@ +import { useState } from 'react'; import './App.css'; +import ChatLog from './components/ChatLog'; +import messages from './data/messages.json'; const App = () => { + const [counter, setCounter] = useState(0); // Initial counter set to 0 + + const onLike = () => { + setCounter((prevCounter) => prevCounter + 1); + }; + + const onUnlike = () => { + setCounter((prevCounter) => prevCounter - 1); + }; + + const likes = counter + ' ❤️s'; + return (
+

{likes}

Application title

- {/* 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..8b84d9f22 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,39 @@ +import { useState } from 'react'; +import PropTypes from 'prop-types'; import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; + +const ChatEntry = ({sender, body, timeStamp, onLike, onUnlike}) => { + const [buttonText, setButtonText] = useState('🤍'); + + const onLikeClick = () => { + if (buttonText === '🤍') { + setButtonText('❤️'); + onLike(); + } else { + setButtonText('🤍'); + onUnlike(); + } + }; -const ChatEntry = () => { 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.elementType.isRequired, + onLike: PropTypes.func.isRequired, + onUnlike: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..261533daa --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,34 @@ +import PropTypes from 'prop-types'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ({entries, onLike, onUnlike}) => { + return ( +
+ {entries.map((entry) => ( + + ))} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.node.isRequired, + }).isRequired + ).isRequired, + onLike: PropTypes.func.isRequired, + onUnlike: PropTypes.func.isRequired, +}; + +export default ChatLog;