From b96273b54a9b47c79e0afe40a918f751e82097ae Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 18:02:36 +0100 Subject: Link previous trip shapes for GPS positioning on circular routes (#111) Co-authored-by: Ariel Costas Guerrero Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com> --- src/frontend/app/components/layout/NavBar.tsx | 99 +++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/frontend/app/components/layout/NavBar.tsx (limited to 'src/frontend/app/components/layout/NavBar.tsx') diff --git a/src/frontend/app/components/layout/NavBar.tsx b/src/frontend/app/components/layout/NavBar.tsx new file mode 100644 index 0000000..91c8810 --- /dev/null +++ b/src/frontend/app/components/layout/NavBar.tsx @@ -0,0 +1,99 @@ +import { Map, MapPin, Settings } from "lucide-react"; +import type { LngLatLike } from "maplibre-gl"; +import { useTranslation } from "react-i18next"; +import { Link, useLocation } from "react-router"; +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"; +} + +export default function NavBar({ orientation = "horizontal" }: NavBarProps) { + const { t } = useTranslation(); + const { mapState, updateMapState, mapPositionMode } = useApp(); + const location = useLocation(); + + const navItems = [ + { + name: t("navbar.stops", "Paradas"), + icon: MapPin, + path: "/", + exact: true, + }, + { + name: t("navbar.map", "Mapa"), + icon: Map, + path: "/map", + callback: () => { + if (mapPositionMode !== "gps") { + return; + } + + if (!("geolocation" in navigator)) { + return; + } + + navigator.geolocation.getCurrentPosition( + (position) => { + const { latitude, longitude } = position.coords; + const coords: LngLatLike = [latitude, longitude]; + if (isWithinVigo(coords)) { + updateMapState(coords, 16); + } + }, + () => {} + ); + }, + }, + { + name: t("navbar.settings", "Ajustes"), + icon: Settings, + path: "/settings", + }, + ]; + + return ( + + ); +} -- cgit v1.3