diff --git a/src/App.jsx b/src/App.jsx
index 14a7f684d..a4a4b74cc 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,14 +1,46 @@
import './App.css';
+import ChatLog from './components/ChatLog';
+import DATA from './data/messages.json';
+import { useState } from 'react';
+
+const calculateLikedCount = (entries) => {
+ let likedCount = 0;
+ for (const entry of entries) {
+ if (entry.liked) {
+ likedCount++;
+ }
+ }
+ return likedCount;
+};
const App = () => {
+ const [entries, setEntries] = useState(DATA);
+ const likedCount = calculateLikedCount(entries);
+
+ const likeEntry = (id) => {
+ setEntries((entries) => {
+ return entries.map((entry) => {
+ if (entry.id === id) {
+ return {...entry, liked: !entry.liked};
+ } else {
+ return entry;
+ }
+ });
+ });
+ };
+
return (
-
Replace with name of sender
+
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+
+
);
@@ -15,6 +20,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,
+ onLikeEntry: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.jsx b/src/components/ChatLog.jsx
new file mode 100644
index 000000000..8c385f868
--- /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 = (props) => {
+ const chatEntryComponents = props.entries.map((entry) => {
+ return (
+
+ );
+ });
+ return (
+
+ {chatEntryComponents}
+
+ );
+};
+
+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,
+ onLikeEntry: PropTypes.func.isRequired,
+};
+
+export default ChatLog;