Skip to content

Commit

Permalink
AvalancheForecastZoneMap: update watch/bulletin behavior
Browse files Browse the repository at this point in the history
The warnings endpoint can return three different types of products
(warnings, watches and special bulletins). We only want the map to flash
when there's an active warning.

A small fix to add 1 day to the warning fetch hook for the time machine,
since the NAC API assumes a date and appends a time to it.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Mar 16, 2024
1 parent 2f2c9d3 commit 2588ef3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ eas secret:push --env-file=.env

## Logging

The log level for our logger is set with `$LOG_LEVEL`, the default is `'info'` but it needs to be `'debug'` for the below network bits.

Runtime logging can be enabled in development mode by running `npx expo start` with the following environment variables set:

`$LOG_NETWORK`:
Expand Down
15 changes: 12 additions & 3 deletions components/AvalancheForecastZoneMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,18 @@ export const AvalancheForecastZoneMap: React.FunctionComponent<MapProps> = ({cen
if (!warning) {
return;
}
const mapViewZoneData = zonesById[warning.zone_id];
if (mapViewZoneData && warning.data.expires_time) {
mapViewZoneData.hasWarning = true;
// the warnings endpoint can return warnings, watches and special bulletins; we only want to make the map flash
// when there's an active warning for the zone
if (
'product_type' in warning.data &&
warning.data.product_type === ProductType.Warning &&
'expires_time' in warning.data &&
isAfter(toDate(new Date(warning.data.expires_time), {timeZone: 'UTC'}), requestedTimeToUTCDate(requestedTime))
) {
const mapViewZoneData = zonesById[warning.zone_id];
if (mapViewZoneData) {
mapViewZoneData.hasWarning = true;
}
}
});
const zones = Object.keys(zonesById).map(k => zonesById[k]);
Expand Down
12 changes: 11 additions & 1 deletion components/screens/menu/DeveloperMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,17 @@ export const DeveloperMenu: React.FC<DeveloperMenuProps> = ({staging, setStaging
action: () => {
navigation.navigate('avalancheCenter', {
center_id: 'NWAC',
requestedTime: toISOStringUTC(new Date('2023-02-20T5:21:00-0800')),
requestedTime: toISOStringUTC(new Date('2024-02-27T15:21:00-0800')),
});
},
},
{
label: 'View map layer with active watch',
data: null,
action: () => {
navigation.navigate('avalancheCenter', {
center_id: 'CBAC',
requestedTime: toISOStringUTC(new Date('2023-03-21T5:21:00-0800')),
});
},
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/useAvalancheWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Sentry from '@sentry/react-native';
import {QueryClient, useQuery, UseQueryResult} from '@tanstack/react-query';
import {Logger} from 'browser-bunyan';
import {ClientContext, ClientProps} from 'clientContext';
import {formatDistanceToNowStrict} from 'date-fns';
import {add, formatDistanceToNowStrict} from 'date-fns';
import {safeFetch} from 'hooks/fetch';
import {LoggerContext, LoggerProps} from 'loggerContext';
import {AvalancheCenterID, warningResultSchema, WarningResultWithZone} from 'types/nationalAvalancheCenter';
Expand Down Expand Up @@ -89,7 +89,7 @@ const fetchAvalancheWarning = async (
zone_id: String(zone_id),
};
if (requested_time !== 'latest') {
params['published_time'] = apiDateString(requested_time); // the API accepts a _date_ and appends 19:00 to it for a time...
params['published_time'] = apiDateString(add(requested_time, {days: 1})); // the API accepts a _date_ and appends 19:00 to it for a time...
}
const what = 'avalanche warning';
const thisLogger = logger.child({url: url, params: params, what: what});
Expand Down

0 comments on commit 2588ef3

Please sign in to comment.