diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..a6013bb6f 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,46 @@
+import { useState } from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
+import messages from './data/messages.json'
+
+
+// import data from messages.json
+const LOG = messages;
+
const App = () => {
+ const [entries, setEntries] = useState(LOG);
+
+ // update chat entry => like change
+ const toggleLike = (id) => {
+ const updatedEntries = entries.map(entry => {
+ if (entry.id === id) {
+ // toggle like
+ return {... entry, liked: !entry.liked};
+ } else {
+ // no change
+ return entry;
+ }
+ });
+ // update entries
+ setEntries(updatedEntries);
+ }
+
+ const totalLikes = entries.filter(entry => entry.liked).length;
+
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..48c951b1f
--- /dev/null
+++ b/src/components/ChatLog.jsx
@@ -0,0 +1,37 @@
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+
+
+const ChatLog = ({entries, onLikeToggle}) => {
+ return (
+
+ {entries.map(entry => (
+
+ ))}
+
+ );
+};
+
+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,
+ onLikeToggle: PropTypes.func.isRequired,
+ };
+
+export default ChatLog;
\ No newline at end of file