Skip to content

Commit

Permalink
Adds an codap listener for closing map so we can update the plugin state
Browse files Browse the repository at this point in the history
  • Loading branch information
eireland committed Jan 30, 2024
1 parent d8ab2ba commit f22bc03
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react";
import { initializePlugin } from "@concord-consortium/codap-plugin-api";
import { ClientNotification, addComponentListener, initializePlugin } from "@concord-consortium/codap-plugin-api";
import { LocationPicker } from "./location-picker";
import { DateRange } from "./date-range/date-range";
import { AttributesSelector } from "./attribute-selector";
Expand Down Expand Up @@ -57,7 +57,17 @@ export const App = () => {
addNotificationHandler("notify",
`dataContextChangeNotice[${StationDSName}]`, async (req: any) => {
stationSelectionHandler(req);
});
});
const createMapListener = (listenerRes: ClientNotification) => {
const { values } = listenerRes;
if (values.operation === "delete" && values.type === "DG.MapView" && values.name === "US Weather Stations") {
setState((draft) => {
draft.zoomMap = false;
draft.isMapOpen = false;
});
}
};
addComponentListener(createMapListener);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit f22bc03

Please sign in to comment.