diff --git a/src/App.css b/src/App.css index d97beb4e6..3c33e0ea4 100644 --- a/src/App.css +++ b/src/App.css @@ -28,6 +28,18 @@ #App header section { background-color: #e0ffff; + color: black; + height: 4rem; + font-size: 1.25rem; + display: flex; + justify-content: center; + align-items: center; +} + +#App header section span { + font-size: 1.25rem; + color: rgba(100%, 0%, 0%, 0); + text-shadow: 0 0 0 red; } #App .widget { @@ -35,40 +47,40 @@ line-height: 0.5em; border-radius: 10px; color: black; - font-size:0.8em; + font-size: 0.8em; padding-left: 1em; padding-right: 1em; } #App #heartWidget { font-size: 1.5em; - margin: 1em + margin: 1em; } #App span { - display: inline-block + display: inline-block; } .red { - color: #b22222 + color: #b22222; } .orange { - color: #e6ac00 + color: #e6ac00; } .yellow { - color: #e6e600 + color: #e6e600; } .green { - color: green + color: green; } .blue { - color: blue + color: blue; } .purple { - color: purple -} \ No newline at end of file + color: purple; +} diff --git a/src/App.js b/src/App.js index c10859093..aed526196 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,34 @@ -import React from 'react'; import './App.css'; +import ChatLog from './components/ChatLog'; import chatMessages from './data/messages.json'; +import React, { useState } from 'react'; const App = () => { + const [chatsData, setChatsData] = useState(chatMessages); + + const updateChatsData = (updateChat) => { + const chats = chatsData.map((chat) => { + if (chat.id === updateChat.id) { + return updateChat; + } else { + return chat; + } + }); + setChatsData(chats); + }; + + const heartCounts = chatsData.filter((chat) => chat.liked === true); + return (

Application title

+
+

{heartCounts.length} ❤️s

+
- {/* Wave 01: Render one ChatEntry component - Wave 02: Render ChatLog component */} +
); diff --git a/src/components/ChatEntry.css b/src/components/ChatEntry.css index 05c3baa44..8e9c32cf9 100644 --- a/src/components/ChatEntry.css +++ b/src/components/ChatEntry.css @@ -1,11 +1,11 @@ button { background: none; - color: inherit; - border: none; - padding: 10px; - font: inherit; - cursor: pointer; - outline: inherit; + color: inherit; + border: none; + padding: 10px; + font: inherit; + cursor: pointer; + outline: inherit; } .chat-entry { @@ -97,4 +97,13 @@ button { .chat-entry.remote .entry-bubble:hover::before { background-color: #a9f6f6; -} \ No newline at end of file +} + +.like { + color: white; +} + +.liked { + color: rgba(100%, 0%, 0%, 0); + text-shadow: 0 0 0 red; +} diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index b92f0b7b2..fa8d19ed3 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,22 +1,48 @@ +//Presentational Component import React from 'react'; import './ChatEntry.css'; +import TimeStamp from './TimeStamp'; import PropTypes from 'prop-types'; const ChatEntry = (props) => { + const changeLikeData = () => { + const chatData = { + id: props.id, + sender: props.sender, + body: props.body, + timeStamp: props.timeStamp, + liked: !props.liked, + }; + props.updateChatsData(chatData); + }; + //I was did the recolor heart emoji first. + // const heartColor = props.liked ? 'liked' : 'like'; + + const heartColor = props.liked ? '❤️' : '🤍'; + const messageType = props.sender === 'Vladimir' ? 'local' : 'remote'; + 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 + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool.isRequired, + updateChatsData: PropTypes.func.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 000000000..55ba195d0 --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,37 @@ +//Container Component + +import React from 'react'; +import ChatEntry from './ChatEntry'; +import PropTypes from 'prop-types'; + +const ChatLog = (props) => { + const getChatEntry = props.entries.map((entrie) => { + return ( + + ); + }); + return
{getChatEntry}
; +}; + +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, + }).isRequired + ), + updateChatsData: PropTypes.func.isRequired, +}; + +export default ChatLog; diff --git a/src/components/ChatLog.test.js b/src/components/ChatLog.test.js index 96f89ebc3..8f9af7cc5 100644 --- a/src/components/ChatLog.test.js +++ b/src/components/ChatLog.test.js @@ -1,49 +1,55 @@ -import React from "react"; -import "@testing-library/jest-dom/extend-expect"; -import ChatLog from "./ChatLog"; -import { render, screen } from "@testing-library/react"; +import React from 'react'; +import '@testing-library/jest-dom/extend-expect'; +import ChatLog from './ChatLog'; +import { render, screen } from '@testing-library/react'; const LOG = [ + // need to add id from the message.json { - sender: "Vladimir", - body: "why are you arguing with me", - timeStamp: "2018-05-29T22:49:06+00:00", + id: 1, + sender: 'Vladimir', + body: 'why are you arguing with me', + timeStamp: '2018-05-29T22:49:06+00:00', }, { - sender: "Estragon", - body: "Because you are wrong.", - timeStamp: "2018-05-29T22:49:33+00:00", + id: 2, + sender: 'Estragon', + body: 'Because you are wrong.', + timeStamp: '2018-05-29T22:49:33+00:00', }, { - sender: "Vladimir", - body: "because I am what", - timeStamp: "2018-05-29T22:50:22+00:00", + id: 3, + sender: 'Vladimir', + body: 'because I am what', + timeStamp: '2018-05-29T22:50:22+00:00', }, { - sender: "Estragon", - body: "A robot.", - timeStamp: "2018-05-29T22:52:21+00:00", + id: 4, + sender: 'Estragon', + body: 'A robot.', + timeStamp: '2018-05-29T22:52:21+00:00', }, { - sender: "Vladimir", - body: "Notabot", - timeStamp: "2019-07-23T22:52:21+00:00", + id: 5, + sender: 'Vladimir', + body: 'Notabot', + timeStamp: '2019-07-23T22:52:21+00:00', }, ]; -describe("Wave 02: ChatLog", () => { +describe('Wave 02: ChatLog', () => { beforeEach(() => { render(); }); - test("renders without crashing and shows all the names", () => { + test('renders without crashing and shows all the names', () => { [ { - name: "Vladimir", + name: 'Vladimir', numChats: 3, }, { - name: "Estragon", + name: 'Estragon', numChats: 2, }, ].forEach((person) => { @@ -56,7 +62,7 @@ describe("Wave 02: ChatLog", () => { }); }); - test("renders an empty list without crashing", () => { + test('renders an empty list without crashing', () => { const element = render(); expect(element).not.toBeNull(); });