From 70e1ed595d809499424a253717eaaf4379272e60 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Fri, 3 Jan 2025 11:04:03 -0600 Subject: [PATCH 1/5] rework assignment load validation logic --- app/src/app/utils/api/queries.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/app/utils/api/queries.ts b/app/src/app/utils/api/queries.ts index 165b609b..7cbdc2ec 100644 --- a/app/src/app/utils/api/queries.ts +++ b/app/src/app/utils/api/queries.ts @@ -140,14 +140,19 @@ export const updateAssignments = (mapDocument: DocumentObject) => { }; fetchAssignments.subscribe(assignments => { - if (assignments.data?.length) { - const {loadZoneAssignments, loadedMapId} = useMapStore.getState(); - if (assignments.data[0].document_id === loadedMapId) { - console.log("Map already loaded, skipping assignment load", assignments.data[0].document_id, loadedMapId); - } else { - loadZoneAssignments(assignments.data); - useMapStore.temporal.getState().clear() + if (assignments.data) { + const {loadZoneAssignments, loadedMapId, setAppLoadingState} = useMapStore.getState(); + if (assignments.data?.length && assignments.data[0].document_id === loadedMapId) { + console.log( + 'Map already loaded, skipping assignment load', + assignments.data[0].document_id, + loadedMapId + ); + return; } + loadZoneAssignments(assignments.data); + useMapStore.temporal.getState().clear(); + setAppLoadingState('loaded'); } }); From 01d32330137eb8733a88c769ff57bbd9ba66179c Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Fri, 3 Jan 2025 11:07:55 -0600 Subject: [PATCH 2/5] make sure app is loaded on tab back in --- app/src/app/utils/api/queries.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/app/utils/api/queries.ts b/app/src/app/utils/api/queries.ts index 7cbdc2ec..aa96c38b 100644 --- a/app/src/app/utils/api/queries.ts +++ b/app/src/app/utils/api/queries.ts @@ -148,6 +148,7 @@ fetchAssignments.subscribe(assignments => { assignments.data[0].document_id, loadedMapId ); + setAppLoadingState('loaded'); return; } loadZoneAssignments(assignments.data); From 5259a0e5125005f5f82a7f2e51834020bd022771 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Fri, 3 Jan 2025 11:13:26 -0600 Subject: [PATCH 3/5] clean up --- app/src/app/utils/api/queries.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/app/utils/api/queries.ts b/app/src/app/utils/api/queries.ts index aa96c38b..bfc5c632 100644 --- a/app/src/app/utils/api/queries.ts +++ b/app/src/app/utils/api/queries.ts @@ -148,11 +148,10 @@ fetchAssignments.subscribe(assignments => { assignments.data[0].document_id, loadedMapId ); - setAppLoadingState('loaded'); - return; + } else { + loadZoneAssignments(assignments.data); + useMapStore.temporal.getState().clear(); } - loadZoneAssignments(assignments.data); - useMapStore.temporal.getState().clear(); setAppLoadingState('loaded'); } }); From fd98616f12605e7f17766e5a9e321c952f150dab Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Fri, 3 Jan 2025 11:19:12 -0600 Subject: [PATCH 4/5] prevent duplicate null parent ID --- app/src/app/utils/api/apiHandlers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/app/utils/api/apiHandlers.ts b/app/src/app/utils/api/apiHandlers.ts index 466f5132..fa84f712 100644 --- a/app/src/app/utils/api/apiHandlers.ts +++ b/app/src/app/utils/api/apiHandlers.ts @@ -8,7 +8,7 @@ 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; + const {allPainted, shatterIds} = useMapStore.getState(); const assignmentsVisited = new Set([...allPainted]); const assignments: Assignment[] = []; @@ -33,7 +33,7 @@ export const FormatAssignments = () => { // fill in with nulls removes assignments from backend // otherwise the previous assignment remains assignmentsVisited.forEach(geo_id => { - if (lastSentAssignments.get(geo_id) !== null) { + if (lastSentAssignments.get(geo_id) !== null && !shatterIds.parents.has(geo_id)) { lastSentAssignments.set(geo_id, null); assignments.push({ document_id: useMapStore.getState().mapDocument?.document_id || '', From e1ee045bad401c63b7edb6954a7e5e6fa7c909e1 Mon Sep 17 00:00:00 2001 From: nofurtherinformation Date: Fri, 3 Jan 2025 11:22:52 -0600 Subject: [PATCH 5/5] remove children from all painted --- app/src/app/store/mapStore.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/app/store/mapStore.ts b/app/src/app/store/mapStore.ts index 4b10f110..a0b0e88a 100644 --- a/app/src/app/store/mapStore.ts +++ b/app/src/app/store/mapStore.ts @@ -494,7 +494,7 @@ export const useMapStore = createWithMiddlewares( set({mapLock: false}) }, silentlyHeal: async (document_id, parentsToHeal) => { - const {getMapRef, zoneAssignments, mapDocument} = get() + const {getMapRef, zoneAssignments, mapDocument, shatterMappings, allPainted} = get() const mapRef = getMapRef(); if (!mapRef) return; set({mapLock: true}) @@ -505,6 +505,12 @@ export const useMapStore = createWithMiddlewares( zone: zoneAssignments.get(parentsToHeal[0])!, document_id }); + const children = shatterMappings[parentsToHeal[0]]; + children.forEach(child => { + // remove from allPainted + allPainted.delete(child); + }) + parentsToHeal.forEach(parent => { mapRef?.setFeatureState({ source: BLOCK_SOURCE_ID, @@ -624,6 +630,7 @@ export const useMapStore = createWithMiddlewares( toggleHighlightBrokenDistricts, lockedFeatures, getMapRef, + allPainted } = get(); const idsToCheck = [..._parentsToHeal, ...additionalIds]; const mapRef = getMapRef(); @@ -654,6 +661,13 @@ export const useMapStore = createWithMiddlewares( zone: parentsToHeal[0].zone as any, document_id: mapDocument?.document_id, }); + const children = parentsToHeal.map(f => shatterMappings[f.parentId]) + .forEach(childSet => { + childSet.forEach(child => { + // remove from allPainted + allPainted.delete(child); + }) + }) toggleHighlightBrokenDistricts(r.geoids, false); const newZoneAssignments = new Map(zoneAssignments); const newShatterIds = {