diff --git a/src/App.css b/src/App.css index d97beb4e6..b5f2a5503 100644 --- a/src/App.css +++ b/src/App.css @@ -28,6 +28,7 @@ #App header section { background-color: #e0ffff; + color: black; } #App .widget { @@ -71,4 +72,10 @@ .purple { color: purple +} + +.colorSection { + display: flex; + flex-flow: row; + justify-content: center; } \ No newline at end of file diff --git a/src/App.js b/src/App.js index c10859093..44d9eb32e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,65 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import { useState } from 'react'; +import ColorChoice from './components/ColorChoice'; const App = () => { + const [chatData, setChatData] = useState(chatMessages); + const [localColor, setLocalColor] = useState('green'); + const [remoteColor, setRemoteColor] = useState('blue'); + + const onUpdateLikes = (entryToUpdate) => { + const entries = chatData.map((entry) => { + if (entry.id === entryToUpdate.id) { + return entryToUpdate; + } + return entry; + }); + setChatData(entries); + }; + + const calcTotalLikes = (Data) => { + let totalLikes = 0; + for (const chat of Data) { + if (chat.liked) { + totalLikes += 1; + } + } + return totalLikes; + }; + +const totalLikeCount = calcTotalLikes(chatData); + +const updateLocalColor = (color) => { + setLocalColor(color); +} + +const updateRemoteColor = (color) => { + setRemoteColor(color); +} + + return (
-

Application title

+

Vivi's ChatLogs

+
+
+ +
+
+

{totalLikeCount} ❤️s

+
+
+ +
+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + + {/* pass localcolor & remotecolor to chatentry & chatlog*/}
); 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..34dbdd921 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,47 @@ 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, + onUpdateLikes, localColor, remoteColor }) => { + const onButtonClick = () => { + onUpdateLikes({ + id: id, + sender: sender, + body: body, + timeStamp: timeStamp, + liked: !liked, + }); + }; + + const toggleHeart = liked ? '❤️' : '🤍'; + const chatEntryClass = sender === 'Vladimir' ? 'local' : 'remote'; + const colorClass = chatEntryClass === 'local' ? localColor : remoteColor; + + 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, + onUpdateLikes: PropTypes.func }; + export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..d5d77d03c --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,41 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ({ entries, onUpdateLikes, localColor, remoteColor}) => { + const chatEntryComponents = entries.map((entry) => { + return ( + + ); +}); +return ( +
+ {chatEntryComponents} +
+); +}; + +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, + onUpdateLikes: PropTypes.func +}; + +export default ChatLog; \ No newline at end of file diff --git a/src/components/ColorChoice.js b/src/components/ColorChoice.js new file mode 100644 index 000000000..af96babe0 --- /dev/null +++ b/src/components/ColorChoice.js @@ -0,0 +1,20 @@ +import React from 'react'; + +const ColorChoice = ({setColorCallback}) => { + const onColorClick = (event) => { + setColorCallback(event.target.value); + } + + return ( +
+ + + + + + +
+ ); +}; + +export default ColorChoice;