diff --git a/src/App.js b/src/App.js
index c10859093..dbcb04489 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,46 @@
-import React from 'react';
+import React, { useState } from 'react';
import './App.css';
+import ChatLog from './components/ChatLog';
import chatMessages from './data/messages.json';
+let totalLikes = 0;
+
+const updateLikes = (entryData) => {
+ let likes = 0;
+ for (const entry of entryData) {
+ if (entry.liked) {
+ likes += 1;
+ }
+ }
+ totalLikes = likes;
+};
+
const App = () => {
+ const [entryData, setEntryData] = useState(chatMessages);
+ const updateEntryData = (updatedEntry) => {
+ const entries = entryData.map((chatEntry) => {
+ if (chatEntry.id === updatedEntry.id) {
+ return updatedEntry;
+ } else {
+ return chatEntry;
+ }
+ });
+ setEntryData(entries);
+ updateLikes(entries);
+ };
+
return (
- Application title
+ Chat between Vladimir and Estragon
+
- {/* 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..86d1f6a0a 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,68 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
- return (
-
-
Replace with name of sender
-
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
-
-
- );
+ const onLikeButtonClick = () => {
+ const updatedEntry = {
+ id: props.id,
+ sender: props.sender,
+ body: props.body,
+ timeStamp: props.timeStamp,
+ liked: !props.liked,
+ };
+ props.onUpdate(updatedEntry);
+ };
+
+ const heart = props.liked ? '❤️' : '🤍';
+
+ if (props.sender === 'Vladimir') {
+ return (
+
+
{props.sender}
+
+ {props.body}
+
+
+
+
+
+
+ );
+ } else {
+ return (
+
+
{props.sender}
+
+ {props.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,
+ onUpdate: PropTypes.func.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..dbbbe40a9
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,42 @@
+import React from 'react';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+import './ChatLog.css';
+
+const ChatLog = (props) => {
+ const chatComponents = props.entries.map((chatEntry) => {
+ 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,
+ })
+ ),
+ onUpdateEntry: PropTypes.func.isRequired,
+};
+
+export default ChatLog;