minor changes
This commit is contained in:
12
src/App.js
12
src/App.js
@@ -595,8 +595,16 @@ function App() {
|
|||||||
if (!preferences?.location) {
|
if (!preferences?.location) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const label = inferLocationLabel(preferences.location, stores);
|
const info = inferLocationLabel(preferences.location, stores);
|
||||||
return label ? { ...preferences.location, label } : { ...preferences.location };
|
if (!info) {
|
||||||
|
return { ...preferences.location };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...preferences.location,
|
||||||
|
label: info.label,
|
||||||
|
labelDistanceKm: info.distanceKm,
|
||||||
|
labelWithinRange: info.withinRange !== false
|
||||||
|
};
|
||||||
}, [preferences?.location, stores]);
|
}, [preferences?.location, stores]);
|
||||||
|
|
||||||
const sharedNotificationProps = {
|
const sharedNotificationProps = {
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ const NotificationPanel = ({
|
|||||||
{locationLoading ? (
|
{locationLoading ? (
|
||||||
<p>Standort wird geladen...</p>
|
<p>Standort wird geladen...</p>
|
||||||
) : location ? (
|
) : location ? (
|
||||||
|
<div>
|
||||||
<p>
|
<p>
|
||||||
Aktueller Standort: {location.lat.toFixed(4)}, {location.lon.toFixed(4)}
|
Aktueller Standort: {location.lat.toFixed(4)}, {location.lon.toFixed(4)}
|
||||||
{location.label && (
|
{location.label && (
|
||||||
@@ -218,6 +219,12 @@ const NotificationPanel = ({
|
|||||||
(
|
(
|
||||||
{location.updatedAt ? new Date(location.updatedAt).toLocaleString('de-DE') : 'Zeit unbekannt'})
|
{location.updatedAt ? new Date(location.updatedAt).toLocaleString('de-DE') : 'Zeit unbekannt'})
|
||||||
</p>
|
</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>
|
<p>Kein Standort hinterlegt.</p>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { haversineDistanceKm } from './distance';
|
import { haversineDistanceKm } from './distance';
|
||||||
|
|
||||||
const DEFAULT_MAX_DISTANCE_KM = 60;
|
|
||||||
|
|
||||||
export function inferLocationLabel(location, stores = [], options = {}) {
|
export function inferLocationLabel(location, stores = [], options = {}) {
|
||||||
if (
|
if (
|
||||||
!location ||
|
!location ||
|
||||||
@@ -14,10 +12,6 @@ export function inferLocationLabel(location, stores = [], options = {}) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxDistanceKm = Number.isFinite(options.maxDistanceKm)
|
|
||||||
? options.maxDistanceKm
|
|
||||||
: DEFAULT_MAX_DISTANCE_KM;
|
|
||||||
|
|
||||||
let closest = null;
|
let closest = null;
|
||||||
for (const store of stores) {
|
for (const store of stores) {
|
||||||
const storeLat = Number(store?.location?.lat);
|
const storeLat = Number(store?.location?.lat);
|
||||||
@@ -46,8 +40,7 @@ export function inferLocationLabel(location, stores = [], options = {}) {
|
|||||||
if (labelParts.length === 0 && store.name) {
|
if (labelParts.length === 0 && store.name) {
|
||||||
labelParts.push(store.name);
|
labelParts.push(store.name);
|
||||||
}
|
}
|
||||||
const label =
|
const label = labelParts.length > 0 ? labelParts.join(' • ') : store.name || `Store ${store.id ?? ''}`.trim();
|
||||||
labelParts.length > 0 ? labelParts.join(' • ') : `Store ${store.id ?? ''}`.trim();
|
|
||||||
closest = {
|
closest = {
|
||||||
label,
|
label,
|
||||||
distance
|
distance
|
||||||
@@ -58,8 +51,12 @@ export function inferLocationLabel(location, stores = [], options = {}) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxDistanceKm <= 0 || closest.distance <= maxDistanceKm) {
|
const result = {
|
||||||
return closest.label;
|
label: closest.label,
|
||||||
|
distanceKm: closest.distance
|
||||||
|
};
|
||||||
|
if (Number.isFinite(options.maxDistanceKm)) {
|
||||||
|
result.withinRange = closest.distance <= options.maxDistanceKm;
|
||||||
}
|
}
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user