Add redirect demo
This commit is contained in:
parent
f5629f1def
commit
044f7c78ea
8 changed files with 70 additions and 22 deletions
BIN
frontend/src/assets/img/habitats/07-riparian-bush-hillsides.png
Normal file
BIN
frontend/src/assets/img/habitats/07-riparian-bush-hillsides.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
|
@ -24,20 +24,30 @@ const steps = [
|
|||
export default function StepperWizard(props) {
|
||||
const [activeStep, setActiveStep] = React.useState(0);
|
||||
const [nextDisabled, setNextDisabled] = React.useState(true);
|
||||
const [redirectBack, setRedirectBack] = React.useState(false);
|
||||
|
||||
const resetStepState = () => {
|
||||
setNextDisabled(true);
|
||||
setRedirectBack(false);
|
||||
}
|
||||
|
||||
const handleNext = () => {
|
||||
setActiveStep((prevActiveStep) => prevActiveStep + 1);
|
||||
setNextDisabled(true);
|
||||
if (redirectBack) {
|
||||
setActiveStep((prevActiveStep) => prevActiveStep - 1);
|
||||
} else {
|
||||
setActiveStep((prevActiveStep) => prevActiveStep + 1);
|
||||
}
|
||||
resetStepState();
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
setActiveStep((prevActiveStep) => prevActiveStep - 1);
|
||||
setNextDisabled(true);
|
||||
resetStepState();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setActiveStep(0);
|
||||
setNextDisabled(true);
|
||||
resetStepState();
|
||||
props.resetFilterState()
|
||||
};
|
||||
|
||||
|
@ -55,7 +65,7 @@ export default function StepperWizard(props) {
|
|||
})}
|
||||
</Stepper>
|
||||
<React.Fragment>
|
||||
<CurrentStep {...props} setNextDisabled={setNextDisabled} />
|
||||
<CurrentStep {...props} setNextDisabled={setNextDisabled} setRedirectBack={setRedirectBack} />
|
||||
<Box sx={{ display: 'flex', flexDirection: 'row', pt: 2, pb: 2, paddingRight: '3vw', paddingLeft: '3vw' }}>
|
||||
<Button
|
||||
color="inherit"
|
||||
|
|
|
@ -25,8 +25,17 @@ export default function ZoneSelector(props) {
|
|||
})
|
||||
}
|
||||
|
||||
const setZone = (zoneSegment) => {
|
||||
setZoneSegment(zoneSegment)
|
||||
const setZoneOrRedirect = (zoneSegment) => {
|
||||
const redirectHabitat = zoneSegment && zoneSegment.zone && zoneSegment.zone.redirect_habitat;
|
||||
setZoneSegment(zoneSegment);
|
||||
|
||||
if (redirectHabitat) {
|
||||
props.updateFilterState({ "habitat": { "id": redirectHabitat.id, "name": redirectHabitat.name } });
|
||||
props.setRedirectBack(true)
|
||||
} else {
|
||||
props.updateFilterState({ "zone": zoneSegment.zone });
|
||||
}
|
||||
|
||||
props.setNextDisabled(false);
|
||||
}
|
||||
|
||||
|
@ -39,15 +48,15 @@ export default function ZoneSelector(props) {
|
|||
setImageHeight(newHeight);
|
||||
}
|
||||
|
||||
// Retrieves the habitat image from the api if they are not loaded already
|
||||
// Retrieves the habitat image from the api if it's not loaded already
|
||||
Object.keys(habitatImageObject).length === 0 && getHabitatImage(findAndSetImageHeight)
|
||||
|
||||
// Sets the image height such that the full image always displays on page resize
|
||||
window.addEventListener("resize", () => findAndSetImageHeight(habitatImageFile), false);
|
||||
|
||||
// Temporarily bypass if there is no image available
|
||||
if (props.filters.zone || !props.filters.habitatImage) {
|
||||
setZone(props.filters.zone)
|
||||
if (props.filters.zone || !props.filters.habitatImage || (habitatImageObject && habitatImageObject.image_segments)) {
|
||||
props.setNextDisabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -61,12 +70,6 @@ export default function ZoneSelector(props) {
|
|||
display: 'flex'
|
||||
}
|
||||
|
||||
const selectZone = (zoneSegment) => {
|
||||
// Update the filters for the selected zone and enable the next button
|
||||
setZone(zoneSegment)
|
||||
props.updateFilterState({ "zone": zoneSegment.zone });
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={imageContainer} style={{ width: '100%' }}>
|
||||
<p>{habitatImageObject && habitatImageObject.name}</p>
|
||||
|
@ -80,7 +83,7 @@ export default function ZoneSelector(props) {
|
|||
// Actual zone selector
|
||||
(<div style={stepBackground}>
|
||||
{habitatImageObject && habitatImageObject.image_segments && Array.isArray(habitatImageObject.image_segments) && habitatImageObject.image_segments.map(segment =>
|
||||
<div key={segment.id} onClick={() => { selectZone(segment) }} className={`selectable-section ${selectedZoneSegment === segment.zone ? 'selected-segment' : ''}`} style={{ width: `${segment.segment_percentage_width}%`, height: '100%' }}></div>
|
||||
<div key={segment.id} onClick={() => { setZoneOrRedirect(segment) }} className={`selectable-section ${selectedZoneSegment === segment ? 'selected-segment' : ''}`} style={{ width: `${segment.segment_percentage_width}%`, height: '100%' }}></div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue