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

project-survey-bench-press #455

Open
wants to merge 21 commits into
base: master
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
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Survey form with React

Replace this readme with your own information about your project.
✔️ **Brief**

Start by briefly describing the assignment in a sentence or two. Keep it short and to the point.
This week we will be practicing React state and controlled forms by making a Typeform-like product. Your completed project should consist of at least 3 questions that need to be answered by users.

**What you need to do**

✓ Your survey should consist of at least 3 questions.

✓ At least one question should use radio buttons.

✓ At least one question should use a select dropdown.

✓ There should be a submit button. When pressed your app should hide the input form and show a summary of the user's submissions.

✓ Your site should follow accessibility guidelines

## The problem

Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next?
Trying to learn React. Lot of new stuff...

## View it live

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
https://benchpress1rm.netlify.app
Binary file added code/public/favicon.ico
Binary file not shown.
29 changes: 9 additions & 20 deletions code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Technigo React App</title>
<meta property="og:title" content="Big Dada's Gym">
<meta property="og:description" content="We do the Math - You lift">

Choose a reason for hiding this comment

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

Great job with the og-tags here Peki!

<meta property="og:image" content="/og-image-survey.jpg">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Sora:wght@100;200;300;400;500;600;700;800&family=Work+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<title>Big Dada's Gym</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
Binary file added code/public/og-image-survey.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 54 additions & 3 deletions code/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
import React from 'react';
import React, { useState } from 'react';
import { Name } from './components/Name';
import { Kilograms } from './components/Kilograms';
import { Level } from './components/Level';
import { Reps } from './components/Reps';
import { Result } from './components/Result';

export const App = () => {
const [step, setStep] = useState(1);
const [name, setName] = useState('');
const [kilo, setKilo] = useState('');
const [reps, setReps] = useState('');
const [level, setLevel] = useState();

const handleStepIncrease = () => {
setStep(step + 1);
}

return (
<div>
Find me in src/app.js!
<div className="gym_app_container">

Choose a reason for hiding this comment

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

Nice structure! It's easy to follow what happens in the different steps.

<div className="gym_app">
{step === 1 && (
<Level level={level} setLevel={setLevel} />

)}
{step === 2 && (
<Name name={name} setName={setName} />
)}
{step === 3 && (
<div className="page-one-container">
<p className="page-one-title">All right, </p>
<p className="page-one-title">{name}</p>
<p className="page-three-question">Your best at the gym?</p>
<div className="kg-reps">
<p className="page-three-kg">kg</p>
<p className="page-three-reps">reps</p>
</div>
<div className="set-kg-reps">
<Kilograms kilo={kilo} setKilo={setKilo} />
<Reps className="reps" reps={reps} setReps={setReps} />
</div>
</div>
)}
{step === 4 && (
<Result
name={name}
kilo={kilo}
reps={reps}
level={level} />
)}
{step < 4 && (
<div className="button_container">
{/* <p>Current step: {step}</p> */}
<button className="button-next" type="button" onClick={handleStepIncrease}>Next</button>

Choose a reason for hiding this comment

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

Here I think you could insert a conditional in the button that says something like: ? step === 4 : ' Submit' then the button text change to submit. But maybe this is a design dicision.

</div>
)}
</div>
</div>
);
}
11 changes: 11 additions & 0 deletions code/src/components/Kilograms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

export const Kilograms = ({ kilo, setKilo }) => {
const handleKiloChange = (event) => {
setKilo(event.target.value);
};

return (
<input className="kilograms" type="number" value={kilo} onChange={handleKiloChange} />
);
};
32 changes: 32 additions & 0 deletions code/src/components/Level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'

const levelSelect = ['YES', 'NO']

export const Level = ({ level, setLevel }) => {
const handleLevelSelect = (event) => {
setLevel(event.target.value);
}
return (
<div className="page-one-container">
<h4 className="page-one-title">Bench Press</h4>
<p className="page-one-sub-title">1 RM</p>
<p className="page-one-question">We do the math – you lift!</p>
<form className="yes-no-buttton">
{levelSelect.map((yesorno) => (
<label key={yesorno} htmlFor={`level-select-${yesorno}`}>
<input
className="radio-buttons"
type="radio"
id={`level-select-${yesorno}`}
value={yesorno}
onChange={handleLevelSelect}
checked={level === yesorno} />
{yesorno}
</label>
))}
</form>
</div>
);
};

export default Level
16 changes: 16 additions & 0 deletions code/src/components/Name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

export const Name = ({ name, setName }) => {
const handleNameChange = (event) => {
const limit = 10;
setName(event.target.value.slice(0, limit));
};
return (
<div className="page-one-container">
<h4 className="page-one-title">Bench Press</h4>
<p className="page-one-sub-title">1 RM</p>
<p className="page-two-question">What is your name?</p>
<input className="input-field" type="text" value={name} onChange={handleNameChange} />
</div>
);
}
20 changes: 20 additions & 0 deletions code/src/components/OneRepMax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

export const OneRepMax = ({ kilo, reps }) => {
const resultEpley = (kilo * (1 + reps / 30));
const resultBrzycki = (kilo * (36 / (37 - reps)));
const resultBaechle = (kilo * (1 + 0.033 * reps));
const result = (resultEpley + resultBrzycki + resultBaechle) / 3;
return Math.round(result);
};

export const Result = ({ name, kilo, reps }) => {
const oneRepMax = OneRepMax({ kilo, reps });
return (
<>
<p> OK, here we go {name} </p>
<p> You have already lifted {reps} with {kilo} in the benchpress. </p>
<p> As you consider yourself beginner, your 1 rep max is around {oneRepMax} </p>
</>
);
};
30 changes: 30 additions & 0 deletions code/src/components/Reps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'

export const Reps = ({ reps, setReps }) => {
return (
<form>
<select
className="reps"
onChange={(event) => setReps(event.target.value)}
value={reps}>
<option value="" disabled> </option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</form>
);
};

export default Reps
50 changes: 50 additions & 0 deletions code/src/components/Result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';

Choose a reason for hiding this comment

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

This is impressive Peki! Its easy to follow what happens with the 3 props in the 4 calculations. Even thou my math / workout skills aren't there I understand the results part :)

export const Result = ({ name, kilo, reps }) => {
const resultEpley = (kilo * (1 + reps / 30));
const resultBrzycki = (kilo * (36 / (37 - reps)));
const resultBaechle = (kilo * (1 + 0.033 * reps));
const oneRepMax = (resultEpley + resultBrzycki + resultBaechle) / 3;
console.log(oneRepMax);
return (
<>
<div className="one-rep-max-container">
<p className="one-rep-max-name">{`${name}'s`}</p>
<p className="one-rep-max-text">Bench Press Max</p>
<p className="one-rep-max-kg">{Math.round(oneRepMax)} kg</p>
</div>
<div className="reps-and-worksets-combo">
<div className="one-rep-max-reps-container">
<p className="one-rep-max-reps">2 reps</p>
<p className="one-rep-max-reps">3 reps</p>
<p className="one-rep-max-reps">4 reps</p>
<p className="one-rep-max-reps">5 reps</p>
<p className="one-rep-max-reps">6 reps</p>
<p className="one-rep-max-reps">7 reps</p>
<p className="one-rep-max-reps">8 reps</p>
<p className="one-rep-max-reps">9 reps</p>
<p className="one-rep-max-reps">10 reps</p>
<p className="one-rep-max-reps">11 reps</p>
<p className="one-rep-max-reps">12 reps</p>
</div>
<div className="one-rep-max-workset-container">
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.97)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.94)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.91)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.88)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.86)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.83)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.81)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.79)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.77)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.75)} kg</p>
<p className="one-rep-max-reps">{Math.round(oneRepMax * 0.73)} kg</p>

</div>
</div>
<div className="close_button_container">
<button type="button" className="close_button" onClick={() => window.location.reload()}>X</button>
</div>
</>
);
};
Loading