Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tigers-Samiya-Chatlog #126

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import React from 'react';
import React, { useState } from 'react';
import './App.css';
import chatMessages from './data/messages.json';
// import ChatEntry from './components/ChatEntry';
import ChatLog from './components/ChatLog';

//<ChatEntry
//sender={chatMessages[0].sender}
//body={chatMessages[0].body}
//timeStamp={chatMessages[0].timeStamp}
///>
const App = () => {
const[likesCount,setLikeCount]=useState(0);
const updateLikes=(isLike)=>{
if (isLike){
setLikeCount(likesCount+1);
} else {
setLikeCount(likesCount-1)

}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. However, your program is only changing the state of the likesCount and doesn't ever address the chatMessages. When you change the buttons, the likes will change visually, but each message's backend data will remain unchanged.

return (
<div id="App">
<header>
<h1>Application title</h1>
<h1>Chat between Vladmir and Estragon</h1>
<h2>{likesCount}🤍s</h2>
<h3>ChatLog</h3>
</header>
<main>
{/* Wave 01: Render one ChatEntry component
<ChatLog entries={chatMessages}updateLikes={updateLikes}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done passing parameters via props!

/>
{/* Chatlog
Wave 02: Render ChatLog component */}
</main>
</div>
Expand Down
44 changes: 37 additions & 7 deletions src/components/ChatEntry.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
import React from 'react';
//import React, { useState } from 'react';
import './ChatEntry.css';
import PropTypes from 'prop-types';
import TimeStamp from './TimeStamp';
import {useState} from 'react';


const ChatEntry = (props) => {
const[likeButton,setLikeButton]=useState('🤍');
const clickedToggle=()=>{

if(likeButton==='🤍'){
setLikeButton('❤️')
props.updateLikes(true)
}else{
setLikeButton('🤍')
props.updateLikes(false)
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where you could have used the state that you pass in to handle what your output is. For example, if we had a props parameter called "isLiked," we could have used that in a simple ternary operator to spit out either the liked heart or the unliked heart.



return (
<div className="chat-entry local">
<h2 className="entry-name">Replace with name of sender</h2>
<section className="entry-bubble">
<p>Replace with body of ChatEntry</p>
<p className="entry-time">Replace with TimeStamp component</p>
<button className="like">🤍</button>
<h2 className="entry-name">{props.sender}</h2>
<section className="entry-bubble">{props.body}
<p></p>
<p className="entry-time">
<TimeStamp time={props.timeStamp}/>
</p>
<button className="like" onClick={clickedToggle}>{likeButton}</button>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emember that we have passed down a function that is supposed to handle this for us. If we are having to rewrite this function, we aren't effectively lifting state up.


</section>
</div>
);
};
//eventhandler (on click)====
//for
// const likeTotal(props)=>
//setlikeCount,Likecount)
//

ChatEntry.propTypes = {
//Fill with correct proptypes
id:PropTypes.number.isRequired,
sender:PropTypes.string.isRequired,
body:PropTypes.string.isRequired,
timeStamp:PropTypes.string.isRequired,
likes:PropTypes.bool.isRequired,

};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of proptypes here!

//`ChatEntry` with props `sender`, `body`, and `timeStamp`.

export default ChatEntry;
16 changes: 8 additions & 8 deletions src/components/ChatEntry.test.js
Original file line number Diff line number Diff line change
@@ -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(
<ChatEntry
Expand All @@ -14,15 +14,15 @@ describe("Wave 01: ChatEntry", () => {
);
});

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();
});
});
30 changes: 30 additions & 0 deletions src/components/ChatLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
import ChatEntry from './ChatEntry';
import './ChatLog.css';



const ChatLog=(props)=>{
const entries =props.entries;
return(
<ul className='chat-log'>
{entries.map((entry,id)=>(
<ChatEntry
key={entry.id}
id={entry.id}
sender={entry.sender}
body={entry.body}
timeStamp={entry.timeStamp}
updateLikes={props.updateLikes}
liked={entry.liked}

></ChatEntry>
))}
</ul>

);
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing our proptypes! Other than that, this component is well-written!


export default ChatLog;
48 changes: 24 additions & 24 deletions src/components/ChatLog.test.js
Original file line number Diff line number Diff line change
@@ -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: '2018-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(<ChatLog entries={LOG} />);
});

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) => {
Expand All @@ -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(<ChatLog entries={[]} />);
expect(element).not.toBeNull();
});
Expand Down