Skip to content

Commit

Permalink
cleanup a little
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Aug 16, 2024
1 parent 56709a0 commit 7405f54
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const debouncedUpdateRowSelectionInCodap = debounce((
// But I was unable to find an example of how to select a case by its attribute values
// Next thing for this might be to see if the case ids might be mapped somewhere to the dayOfYear
// It could be a more direct way to select the case rather than two api requests
// TODO: also right now this is only using the dayOfYear attribute to select the case, but it needs to be restricted to location
// TODO: Right now this is only using the dayOfYear attribute to select the case, but it needs to be restricted to location
codapInterface.sendRequest({
action: "get",
resource: `dataContext[${kDataContextName}].collection[${kChildCollectionName}].caseSearch[dayOfYear==${Math.floor(day)}]`
Expand Down Expand Up @@ -74,7 +74,7 @@ export const App: React.FC = () => {
currentLongitude: string,
currentDayOfYear: number
) => {
// TODO: this is a little hacky - we cooerce the numbers to strings to compare them
// TODO: this is a little hacky? we cooerce the numbers to strings to compare them
const rowInLocation = `${currentLatitude},${currentLongitude}` === `${selectedLatitude},${selectedLongitude}`;
const newDayChoice = `${currentDayOfYear}` !== `${selectedDay}`;
if (rowInLocation && newDayChoice) {
Expand Down Expand Up @@ -105,20 +105,23 @@ export const App: React.FC = () => {
useEffect(() => {
const handleDataContextChange = async (listenerRes: ClientNotification) => {
console.log("| dataContextChangeNotice: ", listenerRes);

Check warning on line 107 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 107 in src/components/App.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
// TODO : as per discussion with team, it might be more typical (and compatible with v3 today)
// TODO: as per discussion with team, it might be more typical
// to use the notificaiton as catalyst to ask for state we interested in from CODAP
// rather than try to parse the notification for the data we need

const { resource, values } = listenerRes;
const isResource = resource === `dataContextChangeNotice[${kDataContextName}]`;
if (!isResource || !values.result.success) return;

const casesDeleted = values.operation === "selectCases" && values.result.cases.length === 0
const caseSelected = values.operation === "selectCases" && values.result.cases.length === 1;

// If cases were deleted, we should update the locations list
if (casesDeleted) {
const uniqeLocations = await getUniqueLocationsRef.current();
if (uniqeLocations) setLocations(uniqeLocations);
}
// If a case was selected, we should update the dayOfYear
else if (caseSelected) {
const parentCaseId = values.result.cases[0].parent;
const selectedDay = values.result.cases[0].values.dayOfYear;
Expand All @@ -136,7 +139,6 @@ export const App: React.FC = () => {
}
};
addDataContextChangeListener(kDataContextName, handleDataContextChange);
// TODO: this is kind of working but not sure about how to clean up the listener?
}, [latitude, longitude, dayOfYear]);

const handleTabClick = (tab: "location" | "simulation") => {
Expand Down

0 comments on commit 7405f54

Please sign in to comment.