Skip to content

Commit

Permalink
Add shatter state change to context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Sep 24, 2024
1 parent d79cb20 commit fb1d9e4
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions app/src/app/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ import {
BLOCK_LAYER_ID,
BLOCK_LAYER_ID_CHILD,
} from "@constants/layers";
import { ShatterResult } from "../api/apiHandlers";

export const MapContextMenu: React.FC = () => {
const { mapRef, mapDocument, contextMenu } = useMapStore((state) => {
return {
mapRef: state.mapRef,
mapDocument: state.mapDocument,
contextMenu: state.contextMenu,
};
});
const patchShatter = useMutation({
const { mapRef, mapDocument, contextMenu, shatterIds, setShatterIds } =
useMapStore((state) => {
return {
mapRef: state.mapRef,
mapDocument: state.mapDocument,
contextMenu: state.contextMenu,
shatterIds: state.shatterIds,
setShatterIds: state.setShatterIds,
};
});
const patchShatter = useMutation<ShatterResult>({
mutationFn: patchShatterParents,
onMutate: ({ document_id, geoids }) => {
console.log(
`Shattering parents for ${geoids} in document ${document_id}...`,
`Shattering parents for ${geoids} in document ${document_id}...`
);
},
onError: (error) => {
console.log("Error updating assignments: ", error);
},
onSuccess: (data) => {
console.log(
`Successfully shattered parents into ${data.children.length} children`,
`Successfully shattered parents into ${data.children.length} children`
);
// mapRef?.current?.setFilter(BLOCK_LAYER_ID_CHILD, [
// "match",
Expand All @@ -52,24 +56,32 @@ export const MapContextMenu: React.FC = () => {
// },
// );
// });
console.log(data.parents.geoids);

data.parents.geoids.forEach((parent) =>
mapRef?.current?.setFeatureState(
{
source: BLOCK_SOURCE_ID,
id: parent,
sourceLayer: BLOCK_LAYER_ID,
},
{ selected: false, zone: null },
),
{ selected: false, zone: null }
)
);
mapRef?.current?.setFilter(BLOCK_LAYER_ID, [
"match",
["get", "path"],
data.parents.geoids, // will need to add existing filters
false,
true,
]);

setShatterIds({
parents: [...shatterIds.parents, ...data.parents.geoids],
children: [
...shatterIds.children,
...data.children.map((child) => child.geo_id),
],
});
// mapRef?.current?.setFilter(BLOCK_LAYER_ID, [
// "match",
// ["get", "path"],
// data.parents.geoids, // will need to add existing filters
// false,
// true,
// ]);
},
});

Expand Down

0 comments on commit fb1d9e4

Please sign in to comment.