Skip to content

Commit

Permalink
more consistent setActiveIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Sep 9, 2024
1 parent 16d9879 commit 365a36e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (

const addFeatureToMap = (geojson: GeoJSONChange) => {
resetErrors();
setFeatures(geojson["EPSG:3857"].features);
setActiveIndex((features && features?.length - 2) || activeIndex + 1);
const newFeatures = geojson["EPSG:3857"].features;
setFeatures(newFeatures);
setActiveIndex(newFeatures.length - 1);
};

const addInitialFeaturesToMap = (features: Feature[]) => {
setFeatures(features);
// TODO: setActiveIndex ?
// setActiveIndex(features.length - 1);
};

const addFeatureToForm = () => {
Expand Down Expand Up @@ -212,8 +213,9 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (
resetErrors();
removeFeatureFromForm(index);
removeFeatureFromMap(index);

// Set active index as highest tab after removal, so that when you "add" a new feature the tabs increment correctly
setActiveIndex((features && features.length - 2) || activeIndex - 1);
setActiveIndex((features && features.length - 2) || 0);
};

return (
Expand Down

0 comments on commit 365a36e

Please sign in to comment.