diff --git a/src/App.css b/src/App.css index d97beb4e6..d0dd43e6a 100644 --- a/src/App.css +++ b/src/App.css @@ -5,7 +5,7 @@ #App header { background-color: #222; color: #fff; - padding-bottom: 0.5rem; + padding: 5 rem; position: fixed; width: 100%; z-index: 100; @@ -13,6 +13,13 @@ align-items: center; } +#App .likes-background-color { + background-color: #87cefa; + margin: 0; + border-style: dotted; + border-color: whitesmoke; +} + #App main { padding-left: 2em; padding-right: 2em; @@ -30,6 +37,11 @@ background-color: #e0ffff; } +#App .header-fonts { + font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + font-style:italic; +} + #App .widget { display: inline-block; line-height: 0.5em; diff --git a/src/App.jsx b/src/App.jsx index 14a7f684d..b6014bf00 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,17 +1,61 @@ import './App.css'; +import ChatLog from '/src/components/ChatLog'; +import DATA from '/src/data/messages.json'; +import { useState } from 'react'; + + +function App() { + const [entries, setEntries] = useState(DATA); + const [colors, setTextColor] = useState(DATA); + + const toggleLikeBtnClick= (id) => { + // Refactoring to incorporate func passing state update + setEntries(entries => entries.map(entry=>{ + if (entry.id == id){ + return {...entry, liked: !entry.liked}; + } + else{ + return entry; + } + })); + }; + + const totalLikesCount = entries.reduce((count, entry) => (entry.liked? count+1: count), 0); + + const identifyAllChatMembers = () => { + const senders = [...new Set(entries.map(entry => entry.sender))]; + let participant1 = ''; + let participant2 = ''; + for (const sender of senders) { + if (!participant1) { + participant1 = sender; + } + else if (participant1 && !participant2) { + participant2 = sender; + } + }; + return `${participant1} and ${participant2}`; + }; + -const App = () => { return (
-
-

Application title

+
+

Chat Between {identifyAllChatMembers()}

+

{totalLikesCount} ❤️s

- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} + {/* // Wave 01: Render one ChatEntry component */} + {/* Wave 02: Render ChatLog component */} + + + +
); }; - export default App; diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx index 15c56f96b..68492580c 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,20 +1,38 @@ +import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; import './ChatEntry.css'; -const ChatEntry = () => { + +const ChatEntry = ({id, sender, body, timeStamp, liked, onLikeToggle}) => { + const likeButtonClicked = () => { + onLikeToggle(id); + }; + + const locateSender = () => { + return (sender === 'Estragon')? 'remote': 'local'; + }; + 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, + onLikeToggle: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 000000000..7803fb6d6 --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,37 @@ +import PropTypes from 'prop-types'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = ({entries, onLikeBtnToggle}) =>{ + const chatComponents = entries.map((entry) => { + return( + + ); + }); + + + return ( + <> + + + ); +}; + +ChatLog.propTypes = { +// Implement + entries: PropTypes.arrayOf(PropTypes.shape({ + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired + })).isRequired, + onLikeBtnToggle: PropTypes.func.isRequired, +}; + +export default ChatLog; \ No newline at end of file diff --git a/src/components/ChatLog.test.jsx b/src/components/ChatLog.test.jsx index dfcfeda99..27aa676e8 100644 --- a/src/components/ChatLog.test.jsx +++ b/src/components/ChatLog.test.jsx @@ -1,4 +1,4 @@ -import ChatLog from './ChatLog'; +import ChatLog from '/src/components/ChatLog'; import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; diff --git a/src/components/TimeStamp.jsx b/src/components/TimeStamp.jsx index e8892b4d4..28e985055 100644 --- a/src/components/TimeStamp.jsx +++ b/src/components/TimeStamp.jsx @@ -5,7 +5,6 @@ const TimeStamp = (props) => { const time = DateTime.fromISO(props.time); const absolute = time.toFormat('MMMM Do YYYY, h:mm:ss a'); const relative = time.toRelative(); - return {relative}; };