Google Maps Bug

This commit is contained in:
Eric Gullickson
2025-11-08 12:17:29 -06:00
parent efbe9ba3c0
commit bb4a356b9e
39 changed files with 1175 additions and 449 deletions

View File

@@ -19,6 +19,12 @@ import {
import { useSavedStations } from '../../stations/hooks/useSavedStations';
import { useStationsSearch } from '../../stations/hooks/useStationsSearch';
import { Station, SavedStation, GeolocationCoordinates } from '../../stations/types/stations.types';
import {
resolveSavedStationAddress,
resolveSavedStationCoordinates,
resolveSavedStationName,
resolveSavedStationPlaceId
} from '../../stations/utils/savedStations';
import { LocationData } from '../types/fuel-logs.types';
interface StationPickerProps {
@@ -121,10 +127,18 @@ export const StationPicker: React.FC<StationPickerProps> = ({
// Add saved stations first
if (savedStations && savedStations.length > 0) {
savedStations.forEach((station) => {
const placeId = resolveSavedStationPlaceId(station);
if (!placeId) {
return;
}
const normalizedStation =
station.placeId === placeId ? station : { ...station, placeId };
opts.push({
type: 'saved',
station,
label: station.nickname || station.name,
station: normalizedStation,
label: resolveSavedStationName(normalizedStation),
group: 'Saved Stations'
});
});
@@ -133,7 +147,11 @@ export const StationPicker: React.FC<StationPickerProps> = ({
// Add nearby stations
if (nearbyStations && nearbyStations.length > 0) {
// Filter out stations already in saved list
const savedPlaceIds = new Set(savedStations?.map((s) => s.placeId) || []);
const savedPlaceIds = new Set(
(savedStations || [])
.map((station) => resolveSavedStationPlaceId(station))
.filter((id): id is string => Boolean(id))
);
nearbyStations
.filter((station) => !savedPlaceIds.has(station.placeId))
@@ -171,16 +189,37 @@ export const StationPicker: React.FC<StationPickerProps> = ({
// Selected from options
const { station } = newValue;
if (station) {
onChange({
stationName: station.name,
address: station.address,
googlePlaceId: station.placeId,
coordinates: {
latitude: station.latitude,
longitude: station.longitude
const saved = isSavedStation(station);
const placeId = saved
? resolveSavedStationPlaceId(station) || station.placeId
: station.placeId;
const name = saved ? resolveSavedStationName(station) : station.name;
const address = saved ? resolveSavedStationAddress(station) : station.address;
let latitude = station.latitude;
let longitude = station.longitude;
if ((latitude === undefined || longitude === undefined) && saved) {
const coords = resolveSavedStationCoordinates(station);
if (coords) {
latitude = coords.latitude;
longitude = coords.longitude;
}
}
onChange({
stationName: name,
address,
googlePlaceId: placeId,
coordinates:
latitude !== undefined && longitude !== undefined
? {
latitude,
longitude
}
: undefined
});
setInputValue(station.name);
setInputValue(name);
}
},
[onChange]