minor changes

This commit is contained in:
2025-11-10 21:54:23 +01:00
parent f4a79a6bc4
commit 545074a3b8
3 changed files with 33 additions and 21 deletions

View File

@@ -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 = {

View File

@@ -210,6 +210,7 @@ const NotificationPanel = ({
{locationLoading ? (
<p>Standort wird geladen...</p>
) : location ? (
<div>
<p>
Aktueller Standort: {location.lat.toFixed(4)}, {location.lon.toFixed(4)}
{location.label && (
@@ -218,6 +219,12 @@ const NotificationPanel = ({
(
{location.updatedAt ? new Date(location.updatedAt).toLocaleString('de-DE') : 'Zeit unbekannt'})
</p>
{location.labelDistanceKm !== undefined && (
<p className="text-xs text-blue-800 mt-1">
Nächster bekannte Betrieb ca. {location.labelDistanceKm.toFixed(1)} km entfernt.
</p>
)}
</div>
) : (
<p>Kein Standort hinterlegt.</p>
)}

View File

@@ -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;
}