minor changes
This commit is contained in:
68
src/App.js
68
src/App.js
@@ -5,7 +5,6 @@ import './App.css';
|
||||
import 'react-date-range/dist/styles.css';
|
||||
import 'react-date-range/dist/theme/default.css';
|
||||
import { formatDateValue, formatRangeLabel } from './utils/dateUtils';
|
||||
import { inferLocationLabel } from './utils/locationLabel';
|
||||
import useSyncProgress from './hooks/useSyncProgress';
|
||||
import useNotificationSettings from './hooks/useNotificationSettings';
|
||||
import useConfigManager from './hooks/useConfigManager';
|
||||
@@ -37,6 +36,7 @@ function App() {
|
||||
const [confirmDialog, setConfirmDialog] = useState({ open: false, resolve: null });
|
||||
const [notificationPanelOpen, setNotificationPanelOpen] = useState(false);
|
||||
const [focusedStoreId, setFocusedStoreId] = useState(null);
|
||||
const [nearestStoreLabel, setNearestStoreLabel] = useState(null);
|
||||
const minSelectableDate = useMemo(() => startOfDay(new Date()), []);
|
||||
|
||||
const weekdays = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'];
|
||||
@@ -147,6 +147,51 @@ function App() {
|
||||
finishSyncProgress
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
let aborted = false;
|
||||
async function lookupNearestStore() {
|
||||
if (
|
||||
!authorizedFetch ||
|
||||
!preferences?.location ||
|
||||
!Number.isFinite(preferences.location.lat) ||
|
||||
!Number.isFinite(preferences.location.lon)
|
||||
) {
|
||||
setNearestStoreLabel(null);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
lat: String(preferences.location.lat),
|
||||
lon: String(preferences.location.lon)
|
||||
});
|
||||
const response = await authorizedFetch(`/api/location/nearest-store?${params.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!aborted) {
|
||||
setNearestStoreLabel(
|
||||
data.store
|
||||
? {
|
||||
label: data.store.label,
|
||||
distanceKm: data.store.distanceKm
|
||||
}
|
||||
: null
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!aborted) {
|
||||
setNearestStoreLabel(null);
|
||||
console.error('Standortsuche fehlgeschlagen:', error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
lookupNearestStore();
|
||||
return () => {
|
||||
aborted = true;
|
||||
};
|
||||
}, [authorizedFetch, preferences?.location?.lat, preferences?.location?.lon]);
|
||||
|
||||
const {
|
||||
adminSettings,
|
||||
adminSettingsLoading,
|
||||
@@ -595,17 +640,18 @@ function App() {
|
||||
if (!preferences?.location) {
|
||||
return null;
|
||||
}
|
||||
const info = inferLocationLabel(preferences.location, stores);
|
||||
if (!info) {
|
||||
return { ...preferences.location };
|
||||
if (preferences.location.label) {
|
||||
return preferences.location;
|
||||
}
|
||||
return {
|
||||
...preferences.location,
|
||||
label: info.label,
|
||||
labelDistanceKm: info.distanceKm,
|
||||
labelWithinRange: info.withinRange !== false
|
||||
};
|
||||
}, [preferences?.location, stores]);
|
||||
if (nearestStoreLabel) {
|
||||
return {
|
||||
...preferences.location,
|
||||
label: nearestStoreLabel.label,
|
||||
labelDistanceKm: nearestStoreLabel.distanceKm
|
||||
};
|
||||
}
|
||||
return { ...preferences.location };
|
||||
}, [preferences?.location, nearestStoreLabel]);
|
||||
|
||||
const sharedNotificationProps = {
|
||||
error: notificationError,
|
||||
|
||||
Reference in New Issue
Block a user