-
Notifications
You must be signed in to change notification settings - Fork 435
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
base: master
Are you sure you want to change the base?
Changes from all commits
43f202e
77f9c62
81e5c6e
a156cb2
04ffd91
5262338
f5421e4
fd75cc8
88d6ee5
ed58d0b
0fc6c3f
935042a
6ba893f
811a1ba
5b7fa00
13d928d
f269fa4
57c7e71
cd52f16
c4306e5
18da6c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
); | ||
} |
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} /> | ||
); | ||
}; |
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 |
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> | ||
); | ||
} |
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> | ||
</> | ||
); | ||
}; |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
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!