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

Mm 107 startquizbutton #19

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from "react";
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import './App.scss';
import Home from './Home/Home';
Expand All @@ -9,15 +9,16 @@ import Footer from './Footer/Footer';


function App() {
const [username, setUsername] = useState("");
return (
<div className="App">
<Router>
<Header/>
<Routes>
<Route path='/'
element={<Home />} />
element={<Home username={username} setUsername={setUsername}/>} />
<Route path='/quiz'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job moving the state up here

element={<Quiz />} />
element={<Quiz username={username}/>} />
</Routes>
<Footer />
</Router>
Expand Down
9 changes: 6 additions & 3 deletions src/Home/Home.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { fireEvent, render, screen } from "@testing-library/react";
import Home from "./Home";
import "@testing-library/jest-dom";
import React, { useState } from "react";

test("user's name is displayed on form submission", () => {
render(<Home />);

test.skip("user's name is displayed on form submission", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can actually fully delete this test as it's no longer the expected behaviour

const name = "Luigi";
const [username, setUsername] = useState(name);

render(<Home username={username} setUsername={setUsername}/>);

const textArea = screen.getByLabelText(/Enter name:/);
fireEvent.change(textArea, { target: { value: name }});

Expand Down
27 changes: 22 additions & 5 deletions src/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import DisplayBackgroundImage from '../images/DisplayBackgroundImage';

function Home() {
interface getUserProp{
Copy link
Contributor

Choose a reason for hiding this comment

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

the convention is have the props name be ComponentNameProps - so in this case it would be HomeProps please can you change this to match that

username:string;
setUsername:(uname:string)=>void;
}

function Home(props:getUserProp) {

const [username, setUsername] = useState("");
//const [username, setUsername] = useState("");
Copy link
Contributor

Choose a reason for hiding this comment

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

there are a couple of lines commented out in this file that I think are old code that we're not using.
Let's remove them as it could cause confusion when looking back or editing this code.

const [submitStatus, setSubmitStatus] = useState(false);

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
setSubmitStatus(true);
}

let navigate = useNavigate();
const routeChange = () =>{
let path = '/quiz';
navigate(path);
}

const homeBackgroundImage = DisplayBackgroundImage();

return (
Expand All @@ -21,14 +33,19 @@ function Home() {
<form onSubmit={handleSubmit}>
<label>Enter name:
<input type="text"
value={username}
onChange={username => setUsername(username.target.value)}
value={props.username}
//onChange={username => setUsername(username.target.value)}
onChange={(username) => {props.setUsername(username.target.value)}}
/>
</label>
<button type="submit">Submit</button>
{submitStatus ? <p>Welcome {username}!</p> : null}
{submitStatus ? <p>Welcome {props.username}!</p> : null}
</form>

<button className="startQuizButton" onClick={routeChange}>
Start quiz
</button>

</main>
</>
)
Expand Down
11 changes: 9 additions & 2 deletions src/Quiz/Quiz.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { QuestionDisplay } from "../QuestionDisplay/QuestionDisplay"

export function Quiz () {
interface getUserProp{
Copy link
Contributor

Choose a reason for hiding this comment

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

As above please can you change this to QuizProps to match convention

username:string;
}

export function Quiz (props:getUserProp) {
return (
<QuestionDisplay/>
<div>
User : {props.username}
<QuestionDisplay/>
</div>
)
}
Loading