From 67fd36741d5db87404b737e68d7b11d9caea0259 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 3 Jan 2025 11:14:55 -0600 Subject: [PATCH] [TEST] Minimal partial assignment (#238) --- app/src/app/store/mapStore.ts | 6 ++++++ app/src/app/utils/api/apiHandlers.ts | 29 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/src/app/store/mapStore.ts b/app/src/app/store/mapStore.ts index 08b38ee6..4b10f110 100644 --- a/app/src/app/store/mapStore.ts +++ b/app/src/app/store/mapStore.ts @@ -8,6 +8,7 @@ import { Assignment, DistrictrMap, DocumentObject, + lastSentAssignments, P1TotPopSummaryStats, P4TotPopSummaryStats, ShatterResult, @@ -409,6 +410,7 @@ export const useMapStore = createWithMiddlewares( const initialMapOptions = useMapStore.getInitialState().mapOptions; parentIdCache.clear(); allPainted.clear(); + lastSentAssignments.clear(); setFreshMap(true); resetZoneAssignments(); @@ -776,6 +778,7 @@ export const useMapStore = createWithMiddlewares( if (resetResponse.document_id === document_id) { const initialState = useMapStore.getInitialState(); useMapStore.temporal.getState().clear() + lastSentAssignments.clear(); resetZoneColors({ zoneAssignments, mapRef: getMapRef(), @@ -905,6 +908,7 @@ export const useMapStore = createWithMiddlewares( }); }, loadZoneAssignments: assignments => { + lastSentAssignments.clear(); const zoneAssignments = new Map(); const shatterIds = { parents: new Set(), @@ -914,6 +918,8 @@ export const useMapStore = createWithMiddlewares( assignments.forEach(assignment => { zoneAssignments.set(assignment.geo_id, assignment.zone); + // preload last sent assignments with last fetched assignments + lastSentAssignments.set(assignment.geo_id, assignment.zone); if (assignment.parent_path) { if (!shatterMappings[assignment.parent_path]) { shatterMappings[assignment.parent_path] = new Set([assignment.geo_id]); diff --git a/app/src/app/utils/api/apiHandlers.ts b/app/src/app/utils/api/apiHandlers.ts index 0f26b4d7..466f5132 100644 --- a/app/src/app/utils/api/apiHandlers.ts +++ b/app/src/app/utils/api/apiHandlers.ts @@ -5,6 +5,7 @@ import {getEntryTotal} from '../summaryStats'; import {useChartStore} from '@/app/store/chartStore'; import {NullableZone} from '@/app/constants/types'; +export const lastSentAssignments = new Map(); export const FormatAssignments = () => { // track the geoids that have been painted, but are now not painted const allPainted = useMapStore.getState().allPainted; @@ -19,22 +20,28 @@ export const FormatAssignments = () => { zone: NullableZone; } => { assignmentsVisited.delete(geo_id); - assignments.push({ - document_id: useMapStore.getState().mapDocument?.document_id || '', - geo_id, - zone, - }); + if (lastSentAssignments.get(geo_id) !== zone) { + lastSentAssignments.set(geo_id, zone); + assignments.push({ + document_id: useMapStore.getState().mapDocument?.document_id || '', + geo_id, + zone, + }); + } } ); // fill in with nulls removes assignments from backend // otherwise the previous assignment remains assignmentsVisited.forEach(geo_id => { - assignments.push({ - document_id: useMapStore.getState().mapDocument?.document_id || '', - geo_id, - // @ts-ignore assignment wants to be number - zone: null, - }); + if (lastSentAssignments.get(geo_id) !== null) { + lastSentAssignments.set(geo_id, null); + assignments.push({ + document_id: useMapStore.getState().mapDocument?.document_id || '', + geo_id, + // @ts-ignore assignment wants to be number + zone: null, + }); + } }); return assignments; };