Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for assignment load validation logic #239

Merged
merged 6 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading