From 68b1d80ffac6a8cd4e6d85be101db72a47cd6cba Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Wed, 13 Oct 2021 07:34:38 +1300 Subject: [PATCH] Modify stepper to be linear --- frontend/src/components/Stepper.js | 134 +++++++++-------------------- 1 file changed, 42 insertions(+), 92 deletions(-) diff --git a/frontend/src/components/Stepper.js b/frontend/src/components/Stepper.js index 2a91537..8b76980 100644 --- a/frontend/src/components/Stepper.js +++ b/frontend/src/components/Stepper.js @@ -2,127 +2,77 @@ import * as React from 'react'; import Box from '@mui/material/Box'; import Stepper from '@mui/material/Stepper'; import Step from '@mui/material/Step'; -import StepButton from '@mui/material/StepButton'; +import StepLabel from '@mui/material/StepLabel'; import Button from '@mui/material/Button'; -import Typography from '@mui/material/Typography'; import LocationStep from './steps/Location' import SoilStep from './steps/Soil' import ResultsStep from './steps/Results' -export default function StepperWizard(props) { - const [activeStep, setActiveStep] = React.useState(0); - const [completed, setCompleted] = React.useState({}); - - const steps = [ +const steps = [ {'label': 'Select location', 'component': LocationStep }, {'label': 'Choose soil', 'component': SoilStep }, {'label': 'Choose habitat', 'component': SoilStep }, {'label': 'Select zone', 'component': SoilStep }, {'label': 'Project specifics', 'component': SoilStep }, {'label': 'Summary', 'component': SoilStep } - ]; +]; - const totalSteps = () => { - return steps.length; - }; - - const completedSteps = () => { - return Object.keys(completed).length; - }; - - const isLastStep = () => { - return activeStep === totalSteps() - 1; - }; - - const allStepsCompleted = () => { - return completedSteps() === totalSteps(); - }; +export default function StepperWizard(props) { + const [activeStep, setActiveStep] = React.useState(0); const handleNext = () => { - const newActiveStep = - isLastStep() && !allStepsCompleted() - ? // It's the last step, but not all steps have been completed, - // find the first step that has been completed - steps.findIndex((step, i) => !(i in completed)) - : activeStep + 1; - setActiveStep(newActiveStep); + setActiveStep((prevActiveStep) => prevActiveStep + 1); }; const handleBack = () => { setActiveStep((prevActiveStep) => prevActiveStep - 1); }; - const handleStep = (step) => () => { - setActiveStep(step); - }; - - const handleComplete = () => { - const newCompleted = completed; - newCompleted[activeStep] = true; - setCompleted(newCompleted); - handleNext(); - }; - const handleReset = () => { setActiveStep(0); - setCompleted({}); }; - let CurrentStep = activeStep > totalSteps() ? steps[activeStep].component : steps[totalSteps()-1].component; + let CurrentStep = activeStep >= steps.length ? steps[steps.length-1].component : steps[activeStep].component; return ( - - {steps.map((step, index) => ( - - - {step.label} - - - ))} + + {steps.map((step, index) => { + return ( + + {step.label} + + ); + })} -
- {allStepsCompleted() ? ( - - - - - - - - ) : ( - - - - - - - {activeStep !== steps.length && - (completed[activeStep] ? ( - - Step {activeStep + 1} already completed - - ) : ( - - ))} - - - )} -
+ {activeStep === steps.length ? ( + + + + + + + + ) : ( + + + + + + + + + )}
); }