From f22bc032d140213d05b4a74291b34ace65b72d61 Mon Sep 17 00:00:00 2001 From: eireland Date: Mon, 29 Jan 2024 19:47:22 -0800 Subject: [PATCH] Adds an codap listener for closing map so we can update the plugin state --- src/components/App.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 9e0adda..f06f9fb 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -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"; @@ -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 }, []);