Skip to content

Commit

Permalink
feat: handle unavailable data for current date (#329)
Browse files Browse the repository at this point in the history
* reset date to minus one day up to three times if data was not found

* Restyled by prettier (#330)

Co-authored-by: Restyled.io <commits@restyled.io>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored Nov 1, 2020
1 parent 4f84256 commit 6ef3f91
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/state/thunks/fetchMappedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const fetchAndTransform = async (
return json;
}

if (res.status === 404) {
return undefined;
}

return null;
};

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

const dateResets = new Map();

export function fetchMappedSet(visualId: VisualId, mappingId: string, date: Moment) {
return async (dispatch: ReduxDispatch, getState: () => State) => {
const timeKey = formatUTCDate(date);
Expand All @@ -117,6 +123,27 @@ export function fetchMappedSet(visualId: VisualId, mappingId: string, date: Mome

if (!data || !geojson) {
dispatch(AppApi.popLoading("mappedSet"));

if (data === undefined) {
const resetKey = `${visualId}-${mappingId}`;

if (!dateResets.has(resetKey)) {
dateResets.set(resetKey, 1);
} else {
dateResets.set(resetKey, dateResets.get(resetKey) + 1);
}

if (dateResets.get(resetKey) > 3) {
dispatch(AppApi.setDatasetFound(false));
return;
}

const newDate = date.clone().subtract(1, "days");

dispatch(AppApi.setCurrentDate(newDate));
return;
}

dispatch(AppApi.setDatasetFound(false));
return;
}
Expand Down

0 comments on commit 6ef3f91

Please sign in to comment.