Skip to content

Commit

Permalink
Toggle features from sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrenechea authored and andresgnlez committed Jan 15, 2024
1 parent 8795cec commit c24c3a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/hooks/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ export function useContinuousFeaturesLayers({
return useMemo(() => {
if (!active) return [];

return features.map((fid) => {
const fs = [...features];

fs.reverse();

return fs.map((fid) => {
const {
amountRange,
color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ const TargetAndSPFFeatures = (): JSX.Element => {
const selectedFeaturesMutation = useSaveSelectedFeatures({});

const dispatch = useAppDispatch();

const scenarioSlice = getScenarioEditSlice(sid);
const { setLayerSettings } = scenarioSlice.actions;
const { layerSettings } = useAppSelector((state) => state[`/scenarios/${sid}/edit`]);

const { setSelectedFeatures, setSelectedContinuousFeatures, setLayerSettings } =
scenarioSlice.actions;

const { selectedFeatures, selectedContinuousFeatures, layerSettings } = useAppSelector(
(state) => state[`/scenarios/${sid}/edit`]
);

const allFeaturesQuery = useAllFeatures(
pid,
Expand All @@ -85,7 +89,6 @@ const TargetAndSPFFeatures = (): JSX.Element => {

const targetedFeatures = useMemo(() => {
let parsedData = [];
console.log({ featureValues });
selectedFeaturesQuery.data?.forEach((feature) => {
if (feature.splitFeaturesSelected?.length > 0) {
const featureMetadata = allFeaturesQuery.data?.find(({ id }) => id === feature.id);
Expand Down Expand Up @@ -208,19 +211,38 @@ const TargetAndSPFFeatures = (): JSX.Element => {

const toggleSeeOnMap = useCallback(
(id: Feature['id']) => {
const selectedFeature = targetedFeatures.find(({ id: featureId }) => featureId === id);
const isContinuous =
selectedFeature.amountRange.min !== null && selectedFeature.amountRange.max !== null;
const { color, amountRange } = targetedFeatures.find(({ id: featureId }) => featureId === id);
// const isContinuous =
// selectedFeature.amountRange.min !== null && selectedFeature.amountRange.max !== null;

console.log(id, layerSettings);

const newSelectedFeatures = [...selectedContinuousFeatures];
const isIncluded = newSelectedFeatures.includes(id);

if (!isIncluded) {
newSelectedFeatures.push(id);
} else {
const i = newSelectedFeatures.indexOf(id);
newSelectedFeatures.splice(i, 1);
}
console.log(newSelectedFeatures);
dispatch(setSelectedContinuousFeatures(newSelectedFeatures));

console.log(selectedContinuousFeatures);

dispatch(
setLayerSettings({
id,
settings: {
visibility: layerSettings[id] ? !layerSettings[id].visibility : true,
color: selectedFeature?.color,
...(isContinuous && {
amountRange: selectedFeature.amountRange,
}),
amountRange,
color,

// color: selectedFeature?.color,
// ...(isContinuous && {
// amountRange: selectedFeature.amountRange,
// }),
},
})
);
Expand Down
1 change: 1 addition & 0 deletions app/layout/scenarios/edit/map/legend/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const useFeaturesLegend = () => {
const i = newSelectedFeatures.indexOf(featureId);
newSelectedFeatures.splice(i, 1);
}

dispatch(setSelectedContinuousFeatures(newSelectedFeatures));

dispatch(
Expand Down

0 comments on commit c24c3a8

Please sign in to comment.