diff --git a/src/App.js b/src/App.js index c1085909..fa7a4189 100644 --- a/src/App.js +++ b/src/App.js @@ -1,8 +1,27 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatLog from './components/ChatLog'; +import { useState } from 'react'; + const App = () => { + + const [chatEntries, setChatsLike] = useState(chatMessages) + + const updateLikeData = updatedChat =>{ + const chats = chatEntries.map(chat => { + if (chat.id === updatedChat.id) { + return updatedChat; + }else { + return chat; + } + }); + + setChatsLike(chats) + + } + return (
@@ -11,6 +30,11 @@ const App = () => {
{/* 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..78530453 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,43 @@ import React from 'react'; import './ChatEntry.css'; import PropTypes from 'prop-types'; +import TimeStamp from './TimeStamp' const ChatEntry = (props) => { + + + const updateLikeButtonClick = () =>{ + const updateChat ={ + id : props.id, + sender : props.sender, + body : props.body, + liked : !props.liked, + timeStamp : props.timeStamp, + } + props.onUpdate(updateChat); + } + + const heartColor = props.liked ? '❤️': '🤍'; + 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, + liked: PropTypes.bool.isRequired, + timeStamp: PropTypes.string.isRequired, + onUpdate: PropTypes.func.isRequired }; export default ChatEntry; diff --git a/src/components/ChatLog.css b/src/components/ChatLog.css index 378848d1..eac0e020 100644 --- a/src/components/ChatLog.css +++ b/src/components/ChatLog.css @@ -2,3 +2,9 @@ margin: auto; max-width: 50rem; } + +#ChatLog h2 { + font-size: 1.5em; + text-align: center; + display: inline-block; +} diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..4a71c048 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,53 @@ +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; +import './ChatLog.css' +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const chatLog = 'chat-log'; + let showLike; + console.log(props.entries); + const chatComponents = props.entries.map((chat, index)=> { + const entriesData = [...props.entries]; + const totalLike = [...entriesData].reduce((a,b) => a + (b.liked? 1: 0), 0) + showLike = totalLike === 0? '🤍' : totalLike + ' ❤️s'; + + return ( +
  • +
  • + ); + }); + + return ( +
    +

    + {showLike} +

    + +
    + ) +}; + +ChatLog.propsTypes ={ + chatEntrys: PropTypes.arrayOf(PropTypes.shape({ + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + timestamp: PropTypes.string.isRequired + })), + onUpdateChat: PropTypes.func.isRequired +}; + +export default ChatLog; \ No newline at end of file