diff --git a/src/App.js b/src/App.js index c1085909..094309c6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,26 @@ -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 [likeCount, setLikeCount] = useState(0); + const updateLikeCount = (increment) => { + setLikeCount(likeCount + increment); + }; return (
-

Application title

+

Vladimir and Estragon's Conversation

+

{`${likeCount} ❤️s`}

{/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa4..8064252b 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -8,6 +8,9 @@ button { outline: inherit; } +button.liked { +} + .chat-entry { margin: 1rem; } @@ -97,4 +100,4 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; -} \ No newline at end of file +} diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b..b53a215f 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,45 @@ -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 source = props.sender === 'Vladimir' ? 'local' : 'remote'; + const [liked, setLiked] = useState(props.liked); + const toggleLikeButton = () => { + const heart = document.getElementById(props.id); + setLiked(!liked); + if (liked) { + heart.textContent = '🤍'; + props.onUpdate(-1); + } else { + heart.textContent = '❤️'; + props.onUpdate(1); + } + setLiked(!liked); + }; return ( -
-

Replace with name of sender

+
+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+

+ +

+
); }; ChatEntry.propTypes = { - //Fill with correct proptypes + id: PropTypes.number, + sender: PropTypes.string, + body: PropTypes.string, + timeStamp: PropTypes.string, + liked: PropTypes.bool, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..63fcc0e2 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,35 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry.js'; + +const ChatLog = (props) => { + const chatEntryComponents = props.entries.map((entry) => { + return ( + + ); + }); + return ; +}; + +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, +}; + +export default ChatLog;