minor changes
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
useReactTable
|
useReactTable
|
||||||
} from '@tanstack/react-table';
|
} from '@tanstack/react-table';
|
||||||
import { haversineDistanceKm } from '../utils/distance';
|
import { haversineDistanceKm } from '../utils/distance';
|
||||||
|
import { inferLocationLabel } from '../utils/locationLabel';
|
||||||
import NotificationPanel from './NotificationPanel';
|
import NotificationPanel from './NotificationPanel';
|
||||||
|
|
||||||
const REGION_STORAGE_KEY = 'storeWatchRegionSelection';
|
const REGION_STORAGE_KEY = 'storeWatchRegionSelection';
|
||||||
@@ -130,6 +131,41 @@ const StoreWatchPage = ({
|
|||||||
const combinedLocationError = locationError || locationPromptError;
|
const combinedLocationError = locationError || locationPromptError;
|
||||||
const locationActionBusy = locationSaving || locationPromptPending;
|
const locationActionBusy = locationSaving || locationPromptPending;
|
||||||
const formatCoordinate = (value) => (Number.isFinite(value) ? Number(value).toFixed(4) : '–');
|
const formatCoordinate = (value) => (Number.isFinite(value) ? Number(value).toFixed(4) : '–');
|
||||||
|
const aggregatedRegionStores = useMemo(() => {
|
||||||
|
const list = [];
|
||||||
|
Object.values(storesByRegion).forEach((entry) => {
|
||||||
|
if (Array.isArray(entry?.stores)) {
|
||||||
|
entry.stores.forEach((store) => {
|
||||||
|
if (store) {
|
||||||
|
list.push(store);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}, [storesByRegion]);
|
||||||
|
const proximityLabel = useMemo(() => {
|
||||||
|
if (!userLocation) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return inferLocationLabel(userLocation, aggregatedRegionStores);
|
||||||
|
}, [userLocation, aggregatedRegionStores]);
|
||||||
|
const displayLocation = useMemo(() => {
|
||||||
|
if (!userLocation) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (userLocation.label) {
|
||||||
|
return userLocation;
|
||||||
|
}
|
||||||
|
if (proximityLabel) {
|
||||||
|
return {
|
||||||
|
...userLocation,
|
||||||
|
label: proximityLabel.label,
|
||||||
|
labelDistanceKm: proximityLabel.distanceKm
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return userLocation;
|
||||||
|
}, [userLocation, proximityLabel]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
@@ -893,7 +929,7 @@ const StoreWatchPage = ({
|
|||||||
{notificationPanelOpen && notificationProps && (
|
{notificationPanelOpen && notificationProps && (
|
||||||
<NotificationPanel
|
<NotificationPanel
|
||||||
{...notificationProps}
|
{...notificationProps}
|
||||||
location={userLocation}
|
location={displayLocation}
|
||||||
locationLoading={locationLoading}
|
locationLoading={locationLoading}
|
||||||
locationSaving={locationActionBusy}
|
locationSaving={locationActionBusy}
|
||||||
locationError={combinedLocationError}
|
locationError={combinedLocationError}
|
||||||
|
|||||||
Reference in New Issue
Block a user