diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 000000000..6f3a2913e
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "liveServer.settings.port": 5501
+}
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index c10859093..560be220f 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 ChatEntry from './components/ChatEntry';
+import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';
+// const message = {
+// id: 1,
+// sender: 'Vladimir',
+// body: 'why are you arguing with me',
+// timeStamp: '2018-05-29T22:49:06+00:00',
+// liked: false,
+// };
+
const App = () => {
+ const [chatData, setChatData] = useState(chatMessages);
+ const [numLiked, setNumLiked] = useState(0);
+
+ const updateChatHeart = (updatedChat) => {
+ const chats = chatData.map((chat) => {
+ if (chat.id === updatedChat.id) {
+ if (updatedChat.liked) {
+ setNumLiked(numLiked + 1);
+ } else {
+ setNumLiked(numLiked - 1);
+ }
+ return updatedChat;
+ } else {
+ return chat;
+ }
+ });
+ setChatData(chats);
+ };
return (
- Application title
+ OcelotChat
+ {numLiked} ❤️s
- {/* Wave 01: Render one ChatEntry component
- Wave 02: Render ChatLog component */}
+
);
diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js
index b92f0b7b2..00a5f4892 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,52 @@
-import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
+
+const ChatEntry = ({
+ id,
+ sender,
+ body,
+ timeStamp,
+ liked,
+ onUpdateChatHeart,
+}) => {
+ const updateChatEntry = () => {
+ const updatedChat = {
+ id,
+ sender,
+ body,
+ timeStamp,
+ liked: !liked,
+ };
+ onUpdateChatHeart(updatedChat);
+ };
+
+ const heart = liked ? '❤️' : '🤍';
-const ChatEntry = (props) => {
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,
+ onUpdateChatHeart: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..4dfaf77c7
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import './ChatLog.css';
+import PropTypes from 'prop-types';
+import ChatEntry from './ChatEntry';
+
+const ChatLog = ({ entries, onUpdateChatHeart }) => {
+ const chatEntries = entries.map((entry) => {
+ return (
+
+ );
+ });
+ return
;
+};
+
+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,
+ })
+ ),
+ onUpdateChatHeart: PropTypes.func.isRequired,
+};
+
+export default ChatLog;