Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface Trip {
status: number;
units: string;
language: string;
warnings?: ValhallaWarning[];
}

export interface Location {
Expand Down Expand Up @@ -213,6 +214,11 @@ export interface Address {
country_code: string;
}

export interface ValhallaWarning {
code: number;
text: string;
}

export interface ValhallaRouteResponse {
id: 'valhalla_directions';
trip: Trip;
Expand All @@ -221,6 +227,7 @@ export interface ValhallaRouteResponse {

export interface ValhallaIsochroneResponse extends GeoJSON.FeatureCollection {
id: string;
warnings?: ValhallaWarning[];
}

export interface FetchGeocodeObject {
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/use-directions-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getValhallaUrl,
buildDirectionsRequest,
parseDirectionsGeometry,
showValhallaWarnings,
} from '@/utils/valhalla';
import {
reverse_geocode,
Expand Down Expand Up @@ -68,6 +69,8 @@ async function fetchDirections() {
}
});

showValhallaWarnings(data.trip.warnings);

return data as ParsedDirectionsGeometry;
}

Expand Down
8 changes: 7 additions & 1 deletion src/hooks/use-isochrones-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import type {
Center,
ValhallaIsochroneResponse,
} from '@/components/types';
import { getValhallaUrl, buildIsochronesRequest } from '@/utils/valhalla';
import {
getValhallaUrl,
buildIsochronesRequest,
showValhallaWarnings,
} from '@/utils/valhalla';
import {
reverse_geocode,
forward_geocode,
Expand Down Expand Up @@ -58,6 +62,8 @@ async function fetchIsochrones() {
}
});

showValhallaWarnings(data.warnings);

return data;
}

Expand Down
3 changes: 3 additions & 0 deletions src/hooks/use-optimized-route-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getValhallaUrl,
buildOptimizedRouteRequest,
parseDirectionsGeometry,
showValhallaWarnings,
} from '@/utils/valhalla';
import { filterProfileSettings } from '@/utils/filter-profile-settings';
import { useCommonStore } from '@/stores/common-store';
Expand Down Expand Up @@ -61,6 +62,8 @@ export function useOptimizedRouteQuery() {
decodedGeometry: parseDirectionsGeometry(data),
};

showValhallaWarnings(data.trip.warnings);

return { data: processedData, relevantWaypoints };
},
onSuccess: ({ data, relevantWaypoints }) => {
Expand Down
14 changes: 14 additions & 0 deletions src/utils/valhalla.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { Profile } from '@/stores/common-store';
import { decode } from './polyline';
import { toast } from 'sonner';
import type {
ActiveWaypoint,
ActiveWaypoints,
IsochronesRequestParams,
Settings,
ValhallaWarning,
} from '@/components/types';
import { getBaseUrl } from './base-url';

Expand Down Expand Up @@ -181,3 +183,15 @@ export const makeLocations = (waypoints: ActiveWaypoint[]) => {

return locations;
};

export function showValhallaWarnings(warnings?: ValhallaWarning[]) {
if (!warnings?.length) return;
for (const warning of warnings) {
toast.warning(`Warning (code ${warning.code})`, {
description: warning.text,
position: 'bottom-center',
duration: 5000,
closeButton: true,
});
}
}