Skip to content

Commit 6ef3f91

Browse files
kommanderrestyled-io[bot]restyled-commits
authored
feat: handle unavailable data for current date (#329)
* reset date to minus one day up to three times if data was not found * Restyled by prettier (#330) Co-authored-by: Restyled.io <[email protected]> Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <[email protected]>
1 parent 4f84256 commit 6ef3f91

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/state/thunks/fetchMappedSet.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const fetchAndTransform = async (
3232
return json;
3333
}
3434

35+
if (res.status === 404) {
36+
return undefined;
37+
}
38+
3539
return null;
3640
};
3741

@@ -91,6 +95,8 @@ async function fetchGeo(geo, date, mapping, geos, dispatch): Promise<GeoJSON | u
9195
return geoPromise;
9296
}
9397

98+
const dateResets = new Map();
99+
94100
export function fetchMappedSet(visualId: VisualId, mappingId: string, date: Moment) {
95101
return async (dispatch: ReduxDispatch, getState: () => State) => {
96102
const timeKey = formatUTCDate(date);
@@ -117,6 +123,27 @@ export function fetchMappedSet(visualId: VisualId, mappingId: string, date: Mome
117123

118124
if (!data || !geojson) {
119125
dispatch(AppApi.popLoading("mappedSet"));
126+
127+
if (data === undefined) {
128+
const resetKey = `${visualId}-${mappingId}`;
129+
130+
if (!dateResets.has(resetKey)) {
131+
dateResets.set(resetKey, 1);
132+
} else {
133+
dateResets.set(resetKey, dateResets.get(resetKey) + 1);
134+
}
135+
136+
if (dateResets.get(resetKey) > 3) {
137+
dispatch(AppApi.setDatasetFound(false));
138+
return;
139+
}
140+
141+
const newDate = date.clone().subtract(1, "days");
142+
143+
dispatch(AppApi.setCurrentDate(newDate));
144+
return;
145+
}
146+
120147
dispatch(AppApi.setDatasetFound(false));
121148
return;
122149
}

0 commit comments

Comments
 (0)