Skip to content

Commit

Permalink
getting ready to update but we need access to state
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Aug 15, 2024
1 parent 9522b37 commit 9537a87
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { clsx } from "clsx";
import { ILocation } from "../types";
import { debounce } from "../grasp-seasons/utils/utils";
import { kInitialDimensions, kVersion, kPluginName, kDefaultOnAttributes, kSimulationTabDimensions, kDataContextName } from "../constants";
import { initializePlugin, codapInterface, selectSelf, addDataContextChangeListener, ClientNotification } from "@concord-consortium/codap-plugin-api";
import { initializePlugin, codapInterface, selectSelf, addDataContextChangeListener, ClientNotification, getCaseByID } from "@concord-consortium/codap-plugin-api";
import { useCodapData } from "../hooks/useCodapData";
import { LocationTab } from "./location-tab";
import { SimulationTab } from "./simulation-tab";
Expand Down Expand Up @@ -40,11 +40,19 @@ export const App: React.FC = () => {
};

const handleCaseSelectionInCodap = (_latitude: string, _longitude: string, day: number) => {
console.log("| calling handleCaseSelectionInCodap with: ", _latitude, _longitude, day);
// if user actually selected the case from the same location, then update the day of the year.
if (latitude === _latitude && longitude === _longitude) {
setDayOfYear(day);
console.log("| calling handleCaseSelectionInCodap with selected values: ", _latitude, _longitude, day);

Check warning on line 43 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Unexpected console statement

Check warning on line 43 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
console.log("| matching lat long?: \n current location: ", latitude, longitude, "\n selected location: ", _latitude, _longitude);

Check warning on line 44 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Unexpected console statement

Check warning on line 44 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
console.log("| matching day?: \n current dayOfYear in sim: ", dayOfYear, "\n selected day in codap: ", day);

Check warning on line 45 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Unexpected console statement

Check warning on line 45 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
const correctLocation = latitude === _latitude && longitude === _longitude;
const isNewDay = dayOfYear !== day;
if (correctLocation && isNewDay) {
console.log("| we should update the dayOfYear in the sim tab to day, ", day);

Check warning on line 49 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Unexpected console statement

Check warning on line 49 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
//setDayOfYear(day);
}
// if user actually selected the case from the same location, then update the day of the year.
// if (latitude === _latitude && longitude === _longitude) {
// setDayOfYear(day);
// }
}


Expand All @@ -65,23 +73,28 @@ export const App: React.FC = () => {
}

// TODO: make this more general, and then decipher what to do with the data
const casesDeletedFromCodapListener = async (listenerRes: ClientNotification) => {
const handleDataContextChange = async (listenerRes: ClientNotification) => {
const { resource, values } = listenerRes;
const isResource = resource === `dataContextChangeNotice[${kDataContextName}]`;
if (!isResource) return;
if (!isResource || !values.result.success) return;

const casesDeleted =
values.operation === "selectCases"
&& values.result.cases
&& values.result.cases.length === 0
&& values.result.success;
// Checking if cases were deleted. If they were, we need to update the locations list.
const casesDeleted = values.operation === "selectCases" && values.result.cases.length === 0
const caseSelected = values.operation === "selectCases" && values.result.cases.length === 1;

if ( casesDeleted ) {
const uniqeLocations = await getUniqueLocationsRef.current();
if (uniqeLocations) setLocations(uniqeLocations);
} else if (caseSelected) {
const parentCaseId = values.result.cases[0].parent;
const selectedDay = values.result.cases[0].values.dayOfYear;
const parentCase = await getCaseByID(kDataContextName, parentCaseId);
const selectedLatitude = parentCase.values.case.values.latitude;
const selectedLongitude = parentCase.values.case.values.longitude;
handleCaseSelectionInCodap(selectedLatitude, selectedLongitude, selectedDay);
}
};
addDataContextChangeListener(kDataContextName, casesDeletedFromCodapListener);
addDataContextChangeListener(kDataContextName, handleDataContextChange);
};

initialize();
Expand Down

0 comments on commit 9537a87

Please sign in to comment.