diff --git a/src/App.js b/src/App.js
index c10859093..759f71605 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,44 @@
-import React from 'react';
+import React, { useState } from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';
const App = () => {
+ const [chatData, updateChatData] = useState(chatMessages);
+ const updateLikes = (id) => {
+ const chats = chatData.map((chat) => {
+ if (chat.id === id) {
+ const newChat = { ...chat };
+ newChat.liked = !newChat.liked;
+ return newChat;
+ }
+ return chat;
+ });
+ updateChatData(chats);
+ };
+ const totalLikes = () => {
+ let total = 0;
+ for (let chat of chatData) {
+ if (chat.liked === true) {
+ total += 1;
+ }
+ }
+ return total;
+ };
return (
-
Replace with name of sender
+
+
{sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {body}
+ {chatTime}
+
);
};
ChatEntry.propTypes = {
- //Fill with correct proptypes
+ id: PropTypes.number,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool,
+ onUpdateLikes: PropTypes.func,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..7e029a2d8
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,38 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+import './ChatLog.css';
+
+const ChatLog = ({ entries, onUpdateLikes }) => {
+ const getChatLogJSX = (entries, onUpdateLikes) => {
+ return entries.map((chat) => {
+ return (
+
+ );
+ });
+ };
+ return
{getChatLogJSX(entries, onUpdateLikes)}
;
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number,
+ sender: PropTypes.string.isRequired,
+ body: PropTypes.string.isRequired,
+ timeStamp: PropTypes.string.isRequired,
+ liked: PropTypes.bool,
+ })
+ ).isRequired,
+ onUpdateLikes: PropTypes.func,
+};
+
+export default ChatLog;