diff --git a/src/App.jsx b/src/App.jsx index 14a7f684..b968a810 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,17 +1,37 @@ import './App.css'; +import ChatLog from './components/ChatLog'; +import messages from './data/messages.json'; +import { useState } from 'react'; const App = () => { + const [entries, setEntries] = useState(messages); + + const toggleLike = (id) => { + setEntries(entries.map(entry => + entry.id === id + ? { ...entry, liked: !entry.liked } + : entry + )); + }; + + const totalLikes = entries.filter(entry => entry.liked).length; + return (

Application title

+
+

{totalLikes} ❤️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.jsx b/src/components/ChatEntry.jsx index fe05efa0..6aa2484a 100644 --- a/src/components/ChatEntry.jsx +++ b/src/components/ChatEntry.jsx @@ -1,21 +1,32 @@ +import PropTypes from 'prop-types'; import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; -const ChatEntry = () => { +const ChatEntry = (props) => { return ( - // Replace the outer tag name with a semantic element that fits our use case - -

Replace with name of sender

+
+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{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.isRequired, + onLikeToggle: PropTypes.func.isRequired }; -export default ChatEntry; +export default ChatEntry; \ No newline at end of file diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx new file mode 100644 index 00000000..badedebd --- /dev/null +++ b/src/components/ChatLog.jsx @@ -0,0 +1,35 @@ +import PropTypes from 'prop-types'; +import ChatEntry from './ChatEntry'; + +const ChatLog = (props) => { + return ( +
+ {props.entries.map(message => ( + + ))} +
+ ); +}; + +ChatLog.propTypes = { + entries: PropTypes.arrayOf( + PropTypes.shape({ + id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + }) + ).isRequired, + onLikeToggle: PropTypes.func.isRequired +}; + +export default ChatLog; \ No newline at end of file