From 64bfe6c52d027fc7ca4ab885f6aad1b2da4a7e72 Mon Sep 17 00:00:00 2001 From: Shannon Bellemore Date: Sun, 26 Jun 2022 19:23:59 -0600 Subject: [PATCH 1/4] wave 1 --- src/App.js | 4 +++- src/components/ChatEntry.js | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index c1085909..176286c2 100644 --- a/src/App.js +++ b/src/App.js @@ -1,16 +1,18 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; +import ChatEntry from './components/ChatEntry'; const App = () => { return (
-

Application title

+

ChatEntry

{/* 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..10d4781d 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -1,20 +1,30 @@ 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

+

{props.sender}

-

Replace with body of ChatEntry

-

Replace with TimeStamp component

+

{props.body}

+

+ +

); }; +// const studentComponents = studentData.map(student => { +// return ( +//
  • +// ); +// }); + ChatEntry.propTypes = { //Fill with correct proptypes }; From bd2d0a2aeba1aa380f33f6c19c7e557f9211a63e Mon Sep 17 00:00:00 2001 From: Shannon Bellemore Date: Thu, 30 Jun 2022 00:42:13 -0600 Subject: [PATCH 2/4] wave 2 --- src/App.js | 6 ++-- src/components/ChatEntry.js | 10 +++---- src/components/ChatEntry.test.js | 16 +++++------ src/components/ChatLog.js | 33 ++++++++++++++++++++++ src/components/ChatLog.test.js | 48 ++++++++++++++++---------------- 5 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 src/components/ChatLog.js diff --git a/src/App.js b/src/App.js index 176286c2..01b99aaa 100644 --- a/src/App.js +++ b/src/App.js @@ -1,18 +1,18 @@ import React from 'react'; import './App.css'; import chatMessages from './data/messages.json'; -import ChatEntry from './components/ChatEntry'; +import ChatLog from './components/ChatLog'; const App = () => { return (
    -

    ChatEntry

    +

    Chat Log

    {/* Wave 01: Render one ChatEntry component Wave 02: Render ChatLog component */} - +
    ); diff --git a/src/components/ChatEntry.js b/src/components/ChatEntry.js index 10d4781d..2641d913 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -19,14 +19,12 @@ const ChatEntry = (props) => { ); }; -// const studentComponents = studentData.map(student => { -// return ( -//
  • -// ); -// }); ChatEntry.propTypes = { - //Fill with correct proptypes + id: PropTypes.number.isRequired, + sender: PropTypes.string.isRequired, + body: PropTypes.string.isRequired, + timeStamp: PropTypes.string.isRequired, }; export default ChatEntry; diff --git a/src/components/ChatEntry.test.js b/src/components/ChatEntry.test.js index b69270c0..4a9a2b09 100644 --- a/src/components/ChatEntry.test.js +++ b/src/components/ChatEntry.test.js @@ -1,9 +1,9 @@ -import React from "react"; -import "@testing-library/jest-dom/extend-expect"; -import ChatEntry from "./ChatEntry"; -import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import React from 'react'; +import '@testing-library/jest-dom/extend-expect'; +import ChatEntry from './ChatEntry'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; -describe("Wave 01: ChatEntry", () => { +describe('Wave 01: ChatEntry', () => { beforeEach(() => { render( { ); }); - test("renders without crashing and shows the sender", () => { + test('renders without crashing and shows the sender', () => { expect(screen.getByText(/Joe Biden/)).toBeInTheDocument(); }); - test("that it will display the body", () => { + test('that it will display the body', () => { expect(screen.getByText(/Get out by 8am/)).toBeInTheDocument(); }); - test("that it will display the time", () => { + test('that it will display the time', () => { expect(screen.getByText(/\d+ years ago/)).toBeInTheDocument(); }); }); diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js new file mode 100644 index 00000000..6db758de --- /dev/null +++ b/src/components/ChatLog.js @@ -0,0 +1,33 @@ +import React from 'react'; +import './ChatLog.css'; +import ChatEntry from './ChatEntry'; + +const ChatLog = (props) => { + const chatEntryComponents = props.entries.map((entry) => { + return ( + + + ); + }); + return
    + {chatEntryComponents} +
    +}; + +// import {useState} from 'react'; +// const [petCount, setPetCount] = useState(0); +// const petCat = () => { +// setPetCount(petCount + 1); +// } + +// const studentComponents = studentData.map(student => { +// return ( +//
  • +// ); +// }); + +export default ChatLog; \ No newline at end of file diff --git a/src/components/ChatLog.test.js b/src/components/ChatLog.test.js index 96f89ebc..6e037d1e 100644 --- a/src/components/ChatLog.test.js +++ b/src/components/ChatLog.test.js @@ -1,49 +1,49 @@ -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 = [ { - sender: "Vladimir", - body: "why are you arguing with me", - timeStamp: "2018-05-29T22:49:06+00:00", + sender: 'Vladimir', + body: 'why are you arguing with me', + timeStamp: '018-05-29T22:49:06+00:00', }, { - sender: "Estragon", - body: "Because you are wrong.", - timeStamp: "2018-05-29T22:49:33+00:00", + 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", + 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", + 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", + 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 +56,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(); }); From fdd8c8cd19098d520b2ff01890ecabf96a1d89ce Mon Sep 17 00:00:00 2001 From: Shannon Bellemore Date: Wed, 6 Jul 2022 13:52:58 -0600 Subject: [PATCH 3/4] working on wave 3 still --- src/App.js | 29 ++++++++++++++++++++++++++++- src/components/ChatEntry.js | 10 +++++++++- src/components/ChatLog.js | 15 +++------------ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/App.js b/src/App.js index 01b99aaa..f0bc841e 100644 --- a/src/App.js +++ b/src/App.js @@ -2,17 +2,44 @@ 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 [entries, setEntries] = useState(chatMessages); + + const changeLikes = (id) => { + const newEntry = entries.map((entry) => { + if(entry.id === id) { + entry.liked = !entry.liked; + } + return newEntry + }); + setEntries(newEntry); + }; + + const likeCount = () => { + let likes = 0; + for(const entry of entries) { + if(entry.liked === true) { + likes += 1; + } + } + return likes; + }; + return (

    Chat Log

    +

    {likeCount()} ❤️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 2641d913..062faba1 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -5,6 +5,10 @@ import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { + const likedEntry = () => { + props.changeLikes(props.id) + } + return (

    {props.sender}

    @@ -13,7 +17,9 @@ const ChatEntry = (props) => {

    - +
    ); @@ -25,6 +31,8 @@ ChatEntry.propTypes = { sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, + liked: PropTypes.bool, + changeLikes: PropTypes.func }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 6db758de..62b7920e 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -6,10 +6,13 @@ const ChatLog = (props) => { const chatEntryComponents = props.entries.map((entry) => { return ( + liked={entry.liked} + changeLikes={props.changeLikes} ); }); @@ -18,16 +21,4 @@ const ChatLog = (props) => { }; -// import {useState} from 'react'; -// const [petCount, setPetCount] = useState(0); -// const petCat = () => { -// setPetCount(petCount + 1); -// } - -// const studentComponents = studentData.map(student => { -// return ( -//
  • -// ); -// }); - export default ChatLog; \ No newline at end of file From 4236b10936559494d3e1b89ad7e404ee62829547 Mon Sep 17 00:00:00 2001 From: Shannon Bellemore Date: Thu, 7 Jul 2022 16:28:56 -0600 Subject: [PATCH 4/4] wave 3 all passing --- src/App.js | 32 +++++++++++++++----------------- src/components/ChatEntry.js | 6 +++--- src/components/ChatLog.js | 4 ++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/App.js b/src/App.js index f0bc841e..5b30abbd 100644 --- a/src/App.js +++ b/src/App.js @@ -6,38 +6,36 @@ import {useState} from 'react'; const App = () => { const [entries, setEntries] = useState(chatMessages); + const [likesTotal, setLikesTotal] = useState(0); const changeLikes = (id) => { - const newEntry = entries.map((entry) => { - if(entry.id === id) { + let likeCount = 0; + const newEntries = []; + for(const e of entries) { + const entry = {...e}; + if(id === entry.id) { entry.liked = !entry.liked; - } - return newEntry - }); - setEntries(newEntry); - }; - - const likeCount = () => { - let likes = 0; - for(const entry of entries) { - if(entry.liked === true) { - likes += 1; - } + } + if (entry.liked === true) { + likeCount += 1; + } + newEntries.push(entry); } - return likes; + setEntries(newEntries); + setLikesTotal(likeCount); }; return (

    Chat Log

    -

    {likeCount()} ❤️s

    +

    {likesTotal} ❤️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 062faba1..7b01deb1 100644 --- a/src/components/ChatEntry.js +++ b/src/components/ChatEntry.js @@ -7,7 +7,7 @@ import TimeStamp from './TimeStamp'; const ChatEntry = (props) => { const likedEntry = () => { props.changeLikes(props.id) - } + }; return (
    @@ -27,12 +27,12 @@ const ChatEntry = (props) => { ChatEntry.propTypes = { - id: PropTypes.number.isRequired, + id: PropTypes.number, sender: PropTypes.string.isRequired, body: PropTypes.string.isRequired, timeStamp: PropTypes.string.isRequired, liked: PropTypes.bool, - changeLikes: PropTypes.func + changeLikes: PropTypes.func, }; export default ChatEntry; diff --git a/src/components/ChatLog.js b/src/components/ChatLog.js index 62b7920e..103f185d 100644 --- a/src/components/ChatLog.js +++ b/src/components/ChatLog.js @@ -10,9 +10,9 @@ const ChatLog = (props) => { id={entry.id} sender={entry.sender} body={entry.body} - timeStamp={entry.timeStamp}> + timeStamp={entry.timeStamp} liked={entry.liked} - changeLikes={props.changeLikes} + changeLikes={props.changeLikes}> ); });