diff --git a/src/App.js b/src/App.js index c10859093..a73d97ee8 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,29 @@ -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 likeChangeHandler = (liked) => { + if (liked) { + setTotalLikes((prevTotal) => prevTotal + 1); + } else { + setTotalLikes((prevTotal) => prevTotal - 1); + } + }; + return (
-

Application title

+

Chat between Vladimir and Estragon

+

{totalLikes} ❤️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..41f010cf1 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,15 +1,32 @@ -import React from 'react'; +import React, {useState} from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { + const [liked, setLiked] = useState(false); + + const likeClickHandler = () => { + setLiked((prevLiked) => !prevLiked); + + props.onLikeChange(!liked); + + }; + + const isLocal = props.sender === 'Vladimir'; + const entryClass = `chat-entry ${isLocal ? 'local': 'remote'}`; + return ( -
-

Replace with name of sender

+
+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+ +

+
); @@ -17,6 +34,10 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { //Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + onLikeChange: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..ddcfceafe --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,33 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +const ChatLog = (props) => { + // console.log(props.onLikeChange) + + const chatEntryComponents = props.entries.map((entry) => ( + + )); + + return ( +
+

Conversation

+ {chatEntryComponents} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.array.isRequired, + onLikeChange: PropTypes.func.isRequired, +}; + +export default ChatLog; \ No newline at end of file