diff --git a/src/App.js b/src/App.js index c10859093..8482be6fd 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,31 @@ -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 [likedMessages, setLikedMessages] = useState(0); + + const likeMessage = () => { + setLikedMessages(likedMessages => likedMessages + 1); + }; + + const unlikeMessage = () => { + setLikedMessages(likedMessages => likedMessages - 1); + }; + return (
-

Application title

+

Chat Messages

+

{likedMessages} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..a7736b49c 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,40 @@ -import React from 'react'; +import React, { useState } from 'react'; import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; import PropTypes from 'prop-types'; -const ChatEntry = (props) => { +const ChatEntry = ( { sender, body, timeStamp, likeMessage, unlikeMessage } ) => { + const [hearted, setHearted] = useState(false); + + const toggleHeart = () => { + setHearted(hearted => !hearted); + hearted ? unlikeMessage(): likeMessage(); + }; + + const heartedIcon = hearted ? '❤️' : '🤍'; + return (
-

Replace with name of sender

+

{sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{body}

+

+ +

+
); }; ChatEntry.propTypes = { - //Fill with correct proptypes + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.number.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..6329f1431 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,32 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ( { entries, likeMessage, unlikeMessage } ) => { + const chatEntries = entries.map(entry => { + return ( + + ) + }) + + return ( + <> + {chatEntries} + + ) +}; + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired + }; + +export default ChatLog; \ No newline at end of file