diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..963a81d05 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,32 @@
+import { useState } from 'react';
+import data from './data/messages.json';
+import ChatLog from './components/ChatLog';
import './App.css';
+
+const countLikes = (entries) => {
+ let counts = 0;
+ for( let index = 0; index < entries.length; index++){
+ if(entries[index].liked){
+ counts++;
+ }
+ }
+ return counts;
+}
+
const App = () => {
+ const [entries, setEntries ] = useState(data);
+ const handleClick = (id) => {
+ const updatedEntries = entries.map((entry) => entry.id === id ? {...entry, liked: !entry.liked} : entry);
+ setEntries(updatedEntries);
+ };
return (
- Application title
+ {`${countLikes(entries)} ❤️s`}
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.jsx b/src/components/ChatEntry.jsx
index 15c56f96b..662b2ad56 100644
--- a/src/components/ChatEntry.jsx
+++ b/src/components/ChatEntry.jsx
@@ -1,13 +1,24 @@
+import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
import './ChatEntry.css';
-const ChatEntry = () => {
+const ChatEntry = (props) => {
+ const{
+ sender,
+ body,
+ id,
+ liked,
+ timeStamp,
+ handleClick,
+ } = props;
return (
-
Replace with name of sender
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
);
@@ -15,6 +26,12 @@ const ChatEntry = () => {
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,
+ handleClick: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..71a69a068
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,27 @@
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+
+import './ChatLog.css';
+
+const ChatLog= (props) => {
+ const{
+ entries,
+ handleClick
+ } = props;
+
+ return (
+
+ {
+ entries.length === 0 ? [] : entries.map((entry) => )
+ }
+
+ );
+};
+
+ChatLog.propTypes = {
+ // Fill with correct proptypes
+ entries: PropTypes.array.isRequired,
+ handleClick: PropTypes.func.isRequired,
+};
+
+export default ChatLog;
diff --git a/src/components/ChatLog.test.jsx b/src/components/ChatLog.test.jsx
index dfcfeda99..cffaa8d39 100644
--- a/src/components/ChatLog.test.jsx
+++ b/src/components/ChatLog.test.jsx
@@ -1,6 +1,6 @@
-import ChatLog from './ChatLog';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
+import ChatLog from './ChatLog';
const LOG = [
{