summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-03-13 10:09:30 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-03-13 10:09:30 +0100
commit56c2e739d95dd7b64a7332e2320579925c1751a9 (patch)
tree256127c61846be48b579a2f3e461d3d89feb4adc
parentb3f5bfad9c2d1ac92debb389fd7a774a6cdb5109 (diff)
Refactor geolocation settings across components; improve accuracy and timeout configurations
-rw-r--r--src/frontend/app/components/layout/NavBar.tsx19
-rw-r--r--src/frontend/app/contexts/MapContext.tsx6
-rw-r--r--src/frontend/app/routes/home.tsx5
-rw-r--r--src/frontend/app/routes/planner.tsx6
4 files changed, 14 insertions, 22 deletions
diff --git a/src/frontend/app/components/layout/NavBar.tsx b/src/frontend/app/components/layout/NavBar.tsx
index 57e2f9d..5822ce7 100644
--- a/src/frontend/app/components/layout/NavBar.tsx
+++ b/src/frontend/app/components/layout/NavBar.tsx
@@ -6,21 +6,6 @@ import { usePlanner } from "~/hooks/usePlanner";
import { useApp } from "../../AppContext";
import styles from "./NavBar.module.css";
-// Helper: check if coordinates are within Vigo bounds
-function isWithinVigo(lngLat: LngLatLike): boolean {
- let lng: number, lat: number;
- if (Array.isArray(lngLat)) {
- [lng, lat] = lngLat;
- } else if ("lng" in lngLat && "lat" in lngLat) {
- lng = lngLat.lng;
- lat = lngLat.lat;
- } else {
- return false;
- }
- // Rough bounding box for Vigo
- return lat >= 42.18 && lat <= 42.3 && lng >= -8.78 && lng <= -8.65;
-}
-
interface NavBarProps {
orientation?: "horizontal" | "vertical";
}
@@ -56,9 +41,7 @@ export default function NavBar({ orientation = "horizontal" }: NavBarProps) {
(position) => {
const { latitude, longitude } = position.coords;
const coords: LngLatLike = [latitude, longitude];
- if (isWithinVigo(coords)) {
- updateMapState(coords, 16);
- }
+ updateMapState(coords, 16, "gps");
},
() => {},
{
diff --git a/src/frontend/app/contexts/MapContext.tsx b/src/frontend/app/contexts/MapContext.tsx
index 5fdf676..f888f34 100644
--- a/src/frontend/app/contexts/MapContext.tsx
+++ b/src/frontend/app/contexts/MapContext.tsx
@@ -6,7 +6,6 @@ import {
useState,
type ReactNode,
} from "react";
-import { APP_CONSTANTS } from "~/config/constants";
interface MapState {
paths: Record<string, { center: LngLatLike; zoom: number }>;
@@ -90,6 +89,11 @@ export const MapProvider = ({ children }: { children: ReactNode }) => {
(error) => {
console.error("Error getting location:", error);
setLocationPermission(false);
+ },
+ {
+ enableHighAccuracy: true,
+ maximumAge: Infinity,
+ timeout: 10000,
}
);
}
diff --git a/src/frontend/app/routes/home.tsx b/src/frontend/app/routes/home.tsx
index 0229ad5..45d7ddf 100644
--- a/src/frontend/app/routes/home.tsx
+++ b/src/frontend/app/routes/home.tsx
@@ -47,7 +47,8 @@ export default function StopList() {
},
{
enableHighAccuracy: false,
- maximumAge: 5 * 60 * 1000,
+ maximumAge: Infinity,
+ timeout: 10000,
}
);
}, []);
@@ -317,7 +318,7 @@ export default function StopList() {
<StopItem
key={stop.stopId}
stop={stop}
- showArrivals={index < 3}
+ showArrivals={index < 5}
/>
))}
</ul>
diff --git a/src/frontend/app/routes/planner.tsx b/src/frontend/app/routes/planner.tsx
index 7bfc5a3..b7ecaf9 100644
--- a/src/frontend/app/routes/planner.tsx
+++ b/src/frontend/app/routes/planner.tsx
@@ -831,7 +831,11 @@ export default function PlannerPage() {
() => {
// If geolocation fails, just keep origin empty
},
- { enableHighAccuracy: true, timeout: 10000 }
+ {
+ enableHighAccuracy: true,
+ timeout: 10000,
+ maximumAge: 60 * 60 * 1000, // 1 hour in milliseconds
+ }
);
}
}}