diff --git a/src/App.css b/src/App.css index d97beb4e6..bdb584363 100644 --- a/src/App.css +++ b/src/App.css @@ -71,4 +71,8 @@ .purple { color: purple -} \ No newline at end of file +} + +/* button like { + +} */ \ No newline at end of file diff --git a/src/App.js b/src/App.js index c10859093..9696aec88 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,35 @@ -import React from 'react'; +import React, {useState} from 'react'; import './App.css'; -import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import HeartCounter from './components/HeartCounter' +import messagesJSON from './data/messages.json' const App = () => { + const [messageData, setMessageData] = useState(messagesJSON); + + const toggleLiked = (id) => { + const messages = messageData.map((message) => { + if (message.id === id) { + message.liked = !message.liked; + } + return message; + }); + + setMessageData(messages); + } + + const totalLikes = messagesJSON.filter(message => message.liked).length; + return ( +
-

Application title

+

Chat with Vladimir

+

+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..622e804ce 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -97,4 +97,9 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; +} + +/* like styles */ +.like { + font-size: small; } \ No newline at end of file diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..b3abaaa23 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,48 @@ -import React from 'react'; +import React, {useState} from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; +import LikeButton from './LikeButton'; + +const setMessageLocation = (userName) => { + + if (userName === 'Vladimir') { + return 'chat-entry local'; + } else if (userName === 'Estragon') { + return 'chat-entry remote'; + }; + +} + +const ChatEntry = ({id, sender, body, timeStamp, isLiked, onLikeMessage}) => { + + const updateLike = () => { + onLikeMessage(id); + }; + + const senderLocation = setMessageLocation(sender); -const ChatEntry = (props) => { 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, + isLiked: PropTypes.bool.isRequired, + onLikeMessage: PropTypes.func.isRequired, }; export default ChatEntry; + diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..1a58af409 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,38 @@ +import React from 'react'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; +import './ChatLog.css'; + +const ChatLog = ({entries, onLikeMessage}) => { + const chatComponents = entries.map((message) => { + return ( +
+ +
+ ); + }); + + return (
+ {chatComponents} +
) +}; + +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 + })), + onLikeMessage: PropTypes.func.isRequired, +}; + +export default ChatLog; \ No newline at end of file diff --git a/src/components/HeartCounter.js b/src/components/HeartCounter.js new file mode 100644 index 000000000..bcc7635fe --- /dev/null +++ b/src/components/HeartCounter.js @@ -0,0 +1,19 @@ +import '../App.css'; +import PropTypes from 'prop-types'; + +const HeartCounter = (props) => { + + return ( +
+

+ {props.likeTotal} ❤️s +

+
+ ); +}; + +HeartCounter.propTypes = { + likeTotal: PropTypes.number.isRequired, +}; + +export default HeartCounter; \ No newline at end of file diff --git a/src/components/LikeButton.js b/src/components/LikeButton.js new file mode 100644 index 000000000..e0e789240 --- /dev/null +++ b/src/components/LikeButton.js @@ -0,0 +1,17 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +const LikeButton = (props) => { + if (props.heartCondition) { + return + } else { + return + }; +}; + +LikeButton.propTypes = { + heartCondition: PropTypes.bool.isRequired, + updateLike: PropTypes.func.isRequired +} + +export default LikeButton; \ No newline at end of file