diff --git a/src/App.js b/src/App.js
index c10859093..c916db67a 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,16 +1,48 @@
-import React from 'react';
+import React, {useState} from 'react';
import './App.css';
import chatMessages from './data/messages.json';
+import ChatLog from './components/ChatLog'
const App = () => {
+
+ const [entries, setEntries] = useState(chatMessages);
+
+ const toggleLike = (id) => {
+ const entriesCopy = entries.map((entry) => {
+ if (entry.id === id) {
+ return {
+ id: entry.id,
+ sender: entry.sender,
+ body: entry.body,
+ timeStamp: entry.timeStamp,
+ liked: !entry.liked
+ };
+ } else return entry;
+ });
+ setEntries(entriesCopy);
+ };
+
+ const countLikes = () => {
+ let counter = 0;
+ for (let entry of entries) {
+ if (entry.liked) {
+ counter += 1;
+ };
+ };
+ return counter;
+ };
+
return (
- Application title
+ Chat Log
+ {countLikes()} ❤️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..a774211cf 100644
--- a/src/components/ChatEntry.js
+++ b/src/components/ChatEntry.js
@@ -1,22 +1,29 @@
import React from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
+import TimeStamp from './TimeStamp';
const ChatEntry = (props) => {
+ const heartIcon = (props.liked) ? '❤️' : '🤍';
+ const messageAlign = (props.sender === 'Vladimir') ? 'remote' : 'local';
return (
-
-
Replace with name of sender
+
+
{props.sender}
- Replace with body of ChatEntry
- Replace with TimeStamp component
-
+ {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.isRequired,
};
export default ChatEntry;
diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js
new file mode 100644
index 000000000..c5c749487
--- /dev/null
+++ b/src/components/ChatLog.js
@@ -0,0 +1,30 @@
+import React from 'react';
+import ChatEntry from './ChatEntry';
+import PropTypes from 'prop-types';
+
+const ChatLog = (props) => {
+
+ const chatComponents = props.entries.map((entry) => {
+ return (
+
+ );
+ });
+ return (
+
+ );
+};
+
+ChatLog.propTypes = {
+ entries: PropTypes.arrayOf(PropTypes.object).isRequired,
+
+};
+
+export default ChatLog;
\ No newline at end of file