diff --git a/src/App.js b/src/App.js index c10859093..7aa414e4c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,30 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatEntry from './components/ChatEntry.js'; +import ChatLog from './components/ChatLog.js'; + + const App = () => { +const [likesCount, setLikesCount] = useState(0); +const updateLikes = (isLike) => { + if (isLike) { + setLikesCount(likesCount + 1); + } else { + setLikesCount(likesCount - 1) + } +} + + return (

Application title

+

{likesCount} ❤️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..f84ffae92 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,44 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp.js'; +import { useState } from 'react'; + + + const ChatEntry = (props) => { + const [likeButton, setLikeButton] = useState('🤍') + const toggleClicked = () => { + if (likeButton === '🤍' ) { + setLikeButton('❤️') + props.updateLikes(true) + } else { + setLikeButton('🤍'); + props.updateLikes(false) + } + + } + + + return (
-

Replace with name of sender

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+
); }; +// {props.updateLikes} ChatEntry.propTypes = { - //Fill with correct proptypes + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..538d0856d --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,29 @@ +import React from 'react'; +import ChatEntry from './ChatEntry'; + + + +const ChatLog = (props) => { + const entries = props.entries; + + return ( +
+ { + entries.map((entry,id) => ( + + ) + )} +
+ ) +}; + + +export default ChatLog;