diff --git a/src/App.css b/src/App.css index d97beb4e6..ec0331526 100644 --- a/src/App.css +++ b/src/App.css @@ -26,6 +26,7 @@ display: inline-block; } + #App header section { background-color: #e0ffff; } @@ -38,6 +39,8 @@ font-size:0.8em; padding-left: 1em; padding-right: 1em; + font-size: 1em; + font-weight: bold; } #App #heartWidget { diff --git a/src/App.js b/src/App.js index c10859093..a76b7476c 100644 --- a/src/App.js +++ b/src/App.js @@ -1,19 +1,58 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog.js'; +import { useState } from 'react'; + const App = () => { + const sender1 = chatMessages[0].sender; + const sender2 = chatMessages[1].sender; + const [chatEntries, setChatEntries] = useState(chatMessages); + const [likes, setLikes] = useState(0); + + const incLikes = () =>{ + setLikes(likes + 1); + }; + + const decLikes = () =>{ + setLikes(likes - 1); + }; + + const updateEntry = updatedEntry => { + const entries = chatEntries.map(entry => { + if (entry.id === updatedEntry.id) { + if (updatedEntry.liked) { + incLikes(); + } + else { + decLikes(); + } + return updatedEntry; + } else { + return entry; + } + }); + setChatEntries(entries) + } + return (
-

Application title

+

Chat between {sender1} and {sender2}

+
+

{likes} ❤️s

+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + {}
); }; -export default App; +export default App; \ No newline at end of file diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..d0e8d6539 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -97,4 +97,5 @@ 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 b92f0b7b2..d6b857252 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'; const ChatEntry = (props) => { + + const onUpdateButtonClick = () => { + const updatedEntry = { + id: props.id, + sender: props.sender, + timeStamp: props.timeStamp, + body: props.body, + liked: !props.isLiked, + sender1: props.localSender + }; + props.onUpdate(updatedEntry); +}; + + const heart = props.isLiked ? '❤️' : '🤍'; + const senderClass = props.sender === props.localSender ? 'chat-entry local' : 'chat-entry remote'; + 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 -}; +/* ChatEntry.propTypes = { + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + isLiked: PropTypes.bool.isRequired, + onUpdate: PropTypes.func.isRequired, + localSender: PropTypes.string.isRequired +}; */ export default ChatEntry; diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1f..a7043e1d1 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -2,3 +2,4 @@ margin: auto; max-width: 50rem; } + diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..1b4e7945c --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,38 @@ +import React from 'react'; +import ChatEntry from './ChatEntry.js'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const chatEntries = props.entries.map((entry) => ( + + + )); + + return ( +
+ {chatEntries} +
+ ); +}; + +/* 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 + })), + onUpdate: PropTypes.func.isRequired, + sender1: PropTypes.func.isRequired +}; + */ +export default ChatLog; \ No newline at end of file