Feat: Geolocation

This commit is contained in:
2025-11-10 17:46:26 +01:00
parent b060e89cef
commit 18ecbac77d

View File

@@ -9,6 +9,8 @@ import {
} from '@tanstack/react-table'; } from '@tanstack/react-table';
import { haversineDistanceKm } from '../utils/distance'; import { haversineDistanceKm } from '../utils/distance';
const REGION_STORAGE_KEY = 'storeWatchRegionSelection';
const columnHelper = createColumnHelper(); const columnHelper = createColumnHelper();
const ColumnTextFilter = ({ column, placeholder }) => { const ColumnTextFilter = ({ column, placeholder }) => {
@@ -48,7 +50,16 @@ const ColumnSelectFilter = ({ column, options }) => {
const StoreWatchPage = ({ authorizedFetch, knownStores = [], userLocation }) => { const StoreWatchPage = ({ authorizedFetch, knownStores = [], userLocation }) => {
const [regions, setRegions] = useState([]); const [regions, setRegions] = useState([]);
const [selectedRegionId, setSelectedRegionId] = useState(''); const [selectedRegionId, setSelectedRegionId] = useState(() => {
if (typeof window === 'undefined') {
return 'all';
}
try {
return window.localStorage.getItem(REGION_STORAGE_KEY) || 'all';
} catch {
return 'all';
}
});
const [storesByRegion, setStoresByRegion] = useState({}); const [storesByRegion, setStoresByRegion] = useState({});
const [watchList, setWatchList] = useState([]); const [watchList, setWatchList] = useState([]);
const [regionLoading, setRegionLoading] = useState(false); const [regionLoading, setRegionLoading] = useState(false);
@@ -61,6 +72,17 @@ const StoreWatchPage = ({ authorizedFetch, knownStores = [], userLocation }) =>
const [sorting, setSorting] = useState([]); const [sorting, setSorting] = useState([]);
const [columnFilters, setColumnFilters] = useState([{ id: 'isOpen', value: 'true' }]); const [columnFilters, setColumnFilters] = useState([{ id: 'isOpen', value: 'true' }]);
useEffect(() => {
if (typeof window === 'undefined') {
return;
}
try {
window.localStorage.setItem(REGION_STORAGE_KEY, selectedRegionId || 'all');
} catch {
/* ignore */
}
}, [selectedRegionId]);
const watchedIds = useMemo( const watchedIds = useMemo(
() => new Set(watchList.map((entry) => String(entry.storeId))), () => new Set(watchList.map((entry) => String(entry.storeId))),
[watchList] [watchList]