From 1c2aedcc9a5383986ef270339db92ff7b3a90bad Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 15 Jun 2026 00:45:06 -0500 Subject: [PATCH] gaslight --- common/params_keys.h | 1 + .../navigation/navigation_destination.js | 20 +++++++++++++++++-- .../the_pond/assets/components/router.js | 2 +- .../system/the_pond/templates/index.html | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/params_keys.h b/common/params_keys.h index 6e2c97871..0ce9c5ba7 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -388,6 +388,7 @@ inline static std::unordered_map keys = { {"AMapKey1", {PERSISTENT | DONT_LOG, STRING, "", "", 0}}, {"AMapKey2", {PERSISTENT | DONT_LOG, STRING, "", "", 0}}, {"ApiCache_NavDestinations", {PERSISTENT, JSON, "[]", "[]"}}, + {"FavoriteDestinations", {PERSISTENT, JSON, "[]", "[]"}}, {"MapAcceleration", {PERSISTENT, BOOL, "0", "0", 1}}, {"MapboxPublicKey", {PERSISTENT | DONT_LOG, STRING, "", "", 0}}, {"MapBoxRequests", {PERSISTENT, JSON, "{}", "{}"}}, diff --git a/starpilot/system/the_pond/assets/components/navigation/navigation_destination.js b/starpilot/system/the_pond/assets/components/navigation/navigation_destination.js index 5e5223f56..682b1e4e8 100644 --- a/starpilot/system/the_pond/assets/components/navigation/navigation_destination.js +++ b/starpilot/system/the_pond/assets/components/navigation/navigation_destination.js @@ -151,6 +151,7 @@ export function NavDestination() { confirmedRoute: null, confirmedRouteRefresh: 0, destination: undefined, + favoriteRoutes: [], favoriteToRemove: null, favoriteToRename: null, favoritesCount: 0, @@ -370,7 +371,12 @@ export function NavDestination() { } function isRouteFavorited(route, favorites) { - return favorites.some(fav => + if (!route || !Array.isArray(route.destinationCoordinates) || route.destinationCoordinates.length !== 2) { + return false; + } + + const favoriteRoutes = Array.isArray(favorites) ? favorites : []; + return favoriteRoutes.some(fav => fav.latitude === route.destinationCoordinates[1] && fav.longitude === route.destinationCoordinates[0] ); @@ -413,8 +419,13 @@ export function NavDestination() { async function loadFavoritesAlphabetically() { try { const res = await fetch("/api/navigation/favorite"); + if (!res.ok) { + throw new Error(`Failed to load favorites: ${res.status}`); + } + const json = await res.json(); - const sorted = json.favorites.sort((a, b) => (a.name || "").localeCompare(b.name || "")); + const favorites = Array.isArray(json?.favorites) ? [...json.favorites] : []; + const sorted = favorites.sort((a, b) => (a.name || "").localeCompare(b.name || "")); state.favoritesCount = sorted.length; state.favoriteRoutes = sorted; addFavoriteMarkers(sorted); @@ -834,6 +845,11 @@ function NavigationDestination({ routeId }) }); + + if (!res.ok) { + throw new Error(`Failed to add favorite: ${res.status}`); + } + const { message } = await res.json(); showSnackbar(message || "Added to favorites!"); await loadFavorites(); diff --git a/starpilot/system/the_pond/assets/components/router.js b/starpilot/system/the_pond/assets/components/router.js index 702eee9fe..f39aab987 100644 --- a/starpilot/system/the_pond/assets/components/router.js +++ b/starpilot/system/the_pond/assets/components/router.js @@ -9,7 +9,7 @@ import { Home } from "/assets/components/home/home.js" import { LateralManeuvers } from "/assets/components/tools/lateral_maneuvers.js" import { LongitudinalManeuvers } from "/assets/components/tools/longitudinal_maneuvers.js" import { MapsManager } from "/assets/components/tools/maps.js" -import { NavDestination } from "/assets/components/navigation/navigation_destination.js" +import { NavDestination } from "/assets/components/navigation/navigation_destination.js?v=nav-favorites-1" import { NavKeys } from "/assets/components/navigation/navigation_keys.js" import { RouteRecordings } from "/assets/components/recordings/dashcam_routes.js" import { SettingsView } from "/assets/components/settings.js" diff --git a/starpilot/system/the_pond/templates/index.html b/starpilot/system/the_pond/templates/index.html index a68587d5d..711b5ff44 100644 --- a/starpilot/system/the_pond/templates/index.html +++ b/starpilot/system/the_pond/templates/index.html @@ -19,7 +19,7 @@ - +