Skip to content

Commit

Permalink
Bugfix for assignment load validation logic (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation authored Jan 3, 2025
1 parent 67fd367 commit a642274
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
16 changes: 15 additions & 1 deletion app/src/app/store/mapStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ export const useMapStore = createWithMiddlewares<MapStore>(
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})
Expand All @@ -505,6 +505,12 @@ export const useMapStore = createWithMiddlewares<MapStore>(
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,
Expand Down Expand Up @@ -624,6 +630,7 @@ export const useMapStore = createWithMiddlewares<MapStore>(
toggleHighlightBrokenDistricts,
lockedFeatures,
getMapRef,
allPainted
} = get();
const idsToCheck = [..._parentsToHeal, ...additionalIds];
const mapRef = getMapRef();
Expand Down Expand Up @@ -654,6 +661,13 @@ export const useMapStore = createWithMiddlewares<MapStore>(
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 = {
Expand Down
4 changes: 2 additions & 2 deletions app/src/app/utils/api/apiHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {NullableZone} from '@/app/constants/types';
export const lastSentAssignments = new Map<string, NullableZone>();
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[] = [];

Expand All @@ -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 || '',
Expand Down
15 changes: 10 additions & 5 deletions app/src/app/utils/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
);
} else {
loadZoneAssignments(assignments.data);
useMapStore.temporal.getState().clear()
useMapStore.temporal.getState().clear();
}
setAppLoadingState('loaded');
}
});

Expand Down

0 comments on commit a642274

Please sign in to comment.