Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
- fix parkingdetails not showing if coordinates are not valid
- fix unique key warnings in ParkingViewServices
  • Loading branch information
mosbuma committed Feb 6, 2024
1 parent d7235d2 commit 03727f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/components/ParkingOnTheMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,16 @@ function ParkingOnTheMap({ parking }) {
if (stateMap) return;

// Get coords from parking variable
const coords = parking.Coordinaten
let coords = parking.Coordinaten
? parking.Coordinaten.split(",").map((coord: any) => Number(coord))
: null; // I.e.: 52.508011,5.473280;

if (coords[0] < -90 || coords[0] > 90 || coords[1] < -180 || coords[1] > 180) {
console.log("***** invalid coordinates for parking", parking.Title, coords);
coords = [52.508011, 5.47328];
return;
}

// otherwise, create a map instance
const mapboxMap = new maplibregl.Map({
container: node,
Expand Down
14 changes: 7 additions & 7 deletions src/components/parking/ParkingViewServices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ import {
} from "~/utils/parkings";

const ParkingViewServices = ({ parkingdata }: { parkingdata: any }) => {
const [allServices, setAllServices ] = React.useState<ServiceType[]>([]);
const [allServices, setAllServices] = React.useState<ServiceType[]>([]);

// Set 'allServices' variable in local state
React.useEffect(() => {
(async () => {
const result = await getAllServices();
setAllServices(result);
})();
},[])
}, [])

const serviceIsActive = (ID: string): boolean => {
for(const x of parkingdata.fietsenstallingen_services) {
if(x.services.ID===ID) {
for (const x of parkingdata.fietsenstallingen_services) {
if (x.services.ID === ID) {
return true;
}
}

return false;
}

if(parkingdata.fietsenstallingen_services===null||parkingdata.fietsenstallingen_services===undefined) {
if (parkingdata.fietsenstallingen_services === null || parkingdata.fietsenstallingen_services === undefined) {
return null
}

return <>
<SectionBlock heading="Services">
<div className="flex-1">
<div className="flex-1" key={'services' + parkingdata.ID}>
{allServices && allServices.map(service => {
if(! serviceIsActive(service.ID)) return <></>
if (!serviceIsActive(service.ID)) return null;
return (
<div key={service.ID}>
{service.Name}
Expand Down

0 comments on commit 03727f5

Please sign in to comment.