diff --git a/src/App.css b/src/App.css index d97beb4e6..e73d4e501 100644 --- a/src/App.css +++ b/src/App.css @@ -28,6 +28,9 @@ #App header section { background-color: #e0ffff; + color: #222; + font-size:1.0em; + font-weight: bold; } #App .widget { diff --git a/src/App.js b/src/App.js index c10859093..fc7fbbb14 100644 --- a/src/App.js +++ b/src/App.js @@ -1,19 +1,45 @@ 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 [entries, setEntriesData] = useState(chatMessages); + const updateLikedCount = (id) => { + setEntriesData((prev) => { + return prev.map((entry) => { + if(id === entry.id) { + return { + ...entry, + liked: !entry.liked, + }; } else { + return entry; + } + }); + }); + } + const totalLikesTally = entries.reduce((total, entry) => { + if (entry.liked === true) { + total += 1; + } + return total; + }, 0); + return (
-

Application title

+

🤖 Chatterbot 🤖

+
{totalLikesTally} ❤️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..40aabde1c 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -27,7 +27,7 @@ button { } .chat-entry .entry-bubble:hover { - background-color: #fefea2; + background-color: hsl(60, 98%, 82%); } .chat-entry .entry-name { diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..230237afc 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,36 @@ import React from 'react'; import './ChatEntry.css'; -import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; +import PropTypes from 'prop-types'; const ChatEntry = (props) => { - return ( -
-

Replace with name of sender

-
-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- -
-
- ); -}; + const onLikeButtonClick = () => { + props.updateLikedCount(props.id); + } + + const formatMessages = props.sender === 'Vladimir' ? 'chat-entry local' : 'chat-entry remote'; + return ( +
+

{props.sender}

+
+

{props.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, + onUpdate: PropTypes.func }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1f..02100de18 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -2,3 +2,5 @@ margin: auto; max-width: 50rem; } + + diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..4441a9ad6 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,36 @@ +import React from 'react'; +import './ChatLog.css'; +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry.js'; + +const ChatLog = (props) => { + const chatComponents = props.entries.map(entry => { + 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 + })) +}; + +export default ChatLog; \ No newline at end of file