diff --git a/src/App.js b/src/App.js index c10859093..189a95452 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,43 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; + const App = () => { + + const [chatData, setChatData] = useState(chatMessages); + let [likeCount, setLikeCount] = useState(0); + // let likeCount = 0; + + const onLikeClick = (id) => { + setChatData(chatData.map(chat => { + if (chat.id === id){ + chat.liked = !chat.liked + if (chat.liked === true){ + setLikeCount(likeCount += 1) + }; + if (chat.liked === false){ + setLikeCount(likeCount -= 1) + }; + + return chat; + } + return chat; +})); +}; + + + return (
-

Application title

+

ChatBug

+

{likeCount} ❤️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..5183420d4 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,29 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; -const ChatEntry = (props) => { +const ChatEntry = ({id, sender, body, timeStamp, liked, onClick}) => { + const heartColor = liked === false ? '🤍' : '❤️'; + const likeButton = () => {onClick(id)}; 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.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + onClick: PropTypes.func.isRequired, }; - export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..e412b991c --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,36 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; +import './ChatLog.css' + +const ChatLog = (props) => { + const getChat = props.entries.map((chat) => { + return ( + + ) + }) + return
{getChat}
+}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + }) + ).isRequired, + onClick: PropTypes.func.isRequired +}; + + +export default ChatLog; \ No newline at end of file