diff --git a/src/App.js b/src/App.js index c1085909..e206d524 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,39 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; -import chatMessages from './data/messages.json'; +import entries from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import ChatEntry from './components/ChatEntry'; + + const App = () => { + const [messages, setMessages] = useState(entries) + + const numLikes = messages.filter((message) => message.liked).length; + + // going to write a helper function for messages + const setLikes = (id) => { + const newMessages = messages.map((message) => { + if (id === message.id){ + return {...message, liked: !message.liked}; + + } + + return message + }); + + setMessages(newMessages) + + } + return (
-

Application title

+

chit chat

+

number of likes {numLikes} ❤️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 b92f0b7b..59e3d8d6 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,31 @@ -import React from 'react'; +import React, { useState } from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { - return ( -
-

Replace with name of sender

+ + + const heart = props.liked? '❤️': '🤍'; + + + return( +
+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

- +

{props.body}

+ +
-
+
); }; ChatEntry.propTypes = { - //Fill with correct proptypes + body: PropTypes.string.isRequired, + sender: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + id: PropTypes.number.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..a69cde1f --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,38 @@ +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + + +const ChatLog = (props) => { + const data = props.entries.map((entry, index) => { + return ( +
  • + +
  • + ); + }); + return ( +
    + +
    + + ); +}; +ChatLog.propTypes = { + entries: PropTypes.arrayOf(PropTypes.shape({ + body: PropTypes.string.isRequired, + sender: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired + })) +}; + +export default ChatLog; diff --git a/src/components/TimeStamp.js b/src/components/TimeStamp.js index e8892b4d..5f475957 100644 --- a/src/components/TimeStamp.js +++ b/src/components/TimeStamp.js @@ -2,11 +2,11 @@ import { DateTime } from 'luxon'; import PropTypes from 'prop-types'; const TimeStamp = (props) => { - const time = DateTime.fromISO(props.time); - const absolute = time.toFormat('MMMM Do YYYY, h:mm:ss a'); - const relative = time.toRelative(); + const compTime = DateTime.fromISO(props.time); + const absolute = compTime.toFormat('MMMM Do YYYY, h:mm:ss a'); + const relative = compTime.toRelative(); - return {relative}; + return {relative}; }; TimeStamp.propTypes = {