diff --git a/src/App.js b/src/App.js index 9643ff6..edae5fe 100644 --- a/src/App.js +++ b/src/App.js @@ -595,8 +595,16 @@ function App() { if (!preferences?.location) { return null; } - const label = inferLocationLabel(preferences.location, stores); - return label ? { ...preferences.location, label } : { ...preferences.location }; + const info = inferLocationLabel(preferences.location, stores); + if (!info) { + return { ...preferences.location }; + } + return { + ...preferences.location, + label: info.label, + labelDistanceKm: info.distanceKm, + labelWithinRange: info.withinRange !== false + }; }, [preferences?.location, stores]); const sharedNotificationProps = { diff --git a/src/components/NotificationPanel.js b/src/components/NotificationPanel.js index cfb6346..c910ce2 100644 --- a/src/components/NotificationPanel.js +++ b/src/components/NotificationPanel.js @@ -210,14 +210,21 @@ const NotificationPanel = ({ {locationLoading ? (

Standort wird geladen...

) : location ? ( -

- Aktueller Standort: {location.lat.toFixed(4)}, {location.lon.toFixed(4)} - {location.label && ( - – {location.label} - )}{' '} - ( - {location.updatedAt ? new Date(location.updatedAt).toLocaleString('de-DE') : 'Zeit unbekannt'}) -

+
+

+ Aktueller Standort: {location.lat.toFixed(4)}, {location.lon.toFixed(4)} + {location.label && ( + – {location.label} + )}{' '} + ( + {location.updatedAt ? new Date(location.updatedAt).toLocaleString('de-DE') : 'Zeit unbekannt'}) +

+ {location.labelDistanceKm !== undefined && ( +

+ Nächster bekannte Betrieb ca. {location.labelDistanceKm.toFixed(1)} km entfernt. +

+ )} +
) : (

Kein Standort hinterlegt.

)} diff --git a/src/utils/locationLabel.js b/src/utils/locationLabel.js index 0b9c9d5..34444f2 100644 --- a/src/utils/locationLabel.js +++ b/src/utils/locationLabel.js @@ -1,7 +1,5 @@ import { haversineDistanceKm } from './distance'; -const DEFAULT_MAX_DISTANCE_KM = 60; - export function inferLocationLabel(location, stores = [], options = {}) { if ( !location || @@ -14,10 +12,6 @@ export function inferLocationLabel(location, stores = [], options = {}) { return null; } - const maxDistanceKm = Number.isFinite(options.maxDistanceKm) - ? options.maxDistanceKm - : DEFAULT_MAX_DISTANCE_KM; - let closest = null; for (const store of stores) { const storeLat = Number(store?.location?.lat); @@ -46,8 +40,7 @@ export function inferLocationLabel(location, stores = [], options = {}) { if (labelParts.length === 0 && store.name) { labelParts.push(store.name); } - const label = - labelParts.length > 0 ? labelParts.join(' • ') : `Store ${store.id ?? ''}`.trim(); + const label = labelParts.length > 0 ? labelParts.join(' • ') : store.name || `Store ${store.id ?? ''}`.trim(); closest = { label, distance @@ -58,8 +51,12 @@ export function inferLocationLabel(location, stores = [], options = {}) { return null; } - if (maxDistanceKm <= 0 || closest.distance <= maxDistanceKm) { - return closest.label; + const result = { + label: closest.label, + distanceKm: closest.distance + }; + if (Number.isFinite(options.maxDistanceKm)) { + result.withinRange = closest.distance <= options.maxDistanceKm; } - return null; + return result; }