From acaeeaf4950a779462186a84ef4ec5974912435e Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Fri, 25 Apr 2025 10:27:44 -0700 Subject: [PATCH] Fix map view on node details --- server/server.go | 5 -- web/.env.example | 4 ++ web/index.html | 6 +- web/src/components/dashboard/NodeDetail.tsx | 3 +- web/src/lib/config.ts | 15 +++-- web/src/types/google-maps.d.ts | 68 +++++++++++++++++++++ 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 web/src/types/google-maps.d.ts diff --git a/server/server.go b/server/server.go index 4809ea9..e12f130 100644 --- a/server/server.go +++ b/server/server.go @@ -155,9 +155,6 @@ func (s *Server) handleStream(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "event: padding\ndata: %s\n\n", padding) flusher.Flush() - // Log that we sent the large initial message - logger.Debug("Sent large initial message to force buffer flush") - // Stream messages to the client for { select { @@ -204,8 +201,6 @@ func (s *Server) handleStream(w http.ResponseWriter, r *http.Request) { return } - logger.Info("Sending packet to client", "packetID", packet.Data.Id) - // Send the event fmt.Fprintf(w, "event: message\ndata: %s\n\n", data) flusher.Flush() diff --git a/web/.env.example b/web/.env.example index 0be1c30..e468852 100644 --- a/web/.env.example +++ b/web/.env.example @@ -5,5 +5,9 @@ VITE_API_BASE_URL="http://localhost:8080" VITE_APP_ENV="development" +# Application customization +VITE_SITE_TITLE="ERSN Mesh" +VITE_SITE_DESCRIPTION="Meshtastic activity in the Ebbett's Pass region of Highway 4, CA." + # Get one at: https://developers.google.com/maps/documentation/javascript/get-api-key VITE_GOOGLE_MAPS_API_KEY=OVERRIDE_IN_LOCAL_ENV \ No newline at end of file diff --git a/web/index.html b/web/index.html index 9a22a74..a6fa64b 100644 --- a/web/index.html +++ b/web/index.html @@ -4,12 +4,14 @@ - - ERSN Mesh + + %VITE_SITE_TITLE% + + diff --git a/web/src/components/dashboard/NodeDetail.tsx b/web/src/components/dashboard/NodeDetail.tsx index 8e8e40d..655a6b4 100644 --- a/web/src/components/dashboard/NodeDetail.tsx +++ b/web/src/components/dashboard/NodeDetail.tsx @@ -13,7 +13,7 @@ interface NodeDetailProps { nodeId: number; } -// Google Maps API is already loaded - this creates a map component +// Google Maps component that uses the API loaded via script tag const GoogleMap: React.FC<{lat: number, lng: number, zoom?: number}> = ({lat, lng, zoom = 14}) => { const mapRef = useRef(null); const mapInstanceRef = useRef(null); @@ -104,7 +104,6 @@ const GoogleMap: React.FC<{lat: number, lng: number, zoom?: number}> = ({lat, ln radius: 300 // 300m accuracy as default }); } - } }, [lat, lng, zoom]); diff --git a/web/src/lib/config.ts b/web/src/lib/config.ts index 9b7792d..3e1b9ba 100644 --- a/web/src/lib/config.ts +++ b/web/src/lib/config.ts @@ -5,20 +5,23 @@ // Environment type export const IS_DEV = import.meta.env.DEV; export const IS_PROD = import.meta.env.PROD; -export const APP_ENV = import.meta.env.VITE_APP_ENV || 'development'; +export const APP_ENV = import.meta.env.VITE_APP_ENV || "development"; // Site configuration -export const SITE_TITLE = import.meta.env.VITE_SITE_TITLE || 'ERSN Mesh'; +export const SITE_TITLE = import.meta.env.VITE_SITE_TITLE || "My Mesh"; +export const SITE_DESCRIPTION = + import.meta.env.VITE_SITE_DESCRIPTION || + "Realtime Meshtastic activity via MQTT."; // API URL configuration const getApiBaseUrl = (): string => { // In production, use the same domain (empty string base URL) if (IS_PROD) { - return import.meta.env.VITE_API_BASE_URL || ''; + return import.meta.env.VITE_API_BASE_URL || ""; } - + // In development, use the configured base URL with fallback - return import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080'; + return import.meta.env.VITE_API_BASE_URL || "http://localhost:8080"; }; export const API_BASE_URL = getApiBaseUrl(); @@ -26,4 +29,4 @@ export const API_BASE_URL = getApiBaseUrl(); // API endpoints export const API_ENDPOINTS = { STREAM: `${API_BASE_URL}/api/stream`, -}; \ No newline at end of file +}; diff --git a/web/src/types/google-maps.d.ts b/web/src/types/google-maps.d.ts new file mode 100644 index 0000000..e302d79 --- /dev/null +++ b/web/src/types/google-maps.d.ts @@ -0,0 +1,68 @@ +// Type definitions for Google Maps JavaScript API +declare namespace google { + namespace maps { + class Map { + constructor( + mapDiv: Element, + opts?: MapOptions + ); + } + + class Marker { + constructor(opts?: MarkerOptions); + } + + class Circle { + constructor(opts?: CircleOptions); + } + + interface MapOptions { + center?: { lat: number; lng: number }; + zoom?: number; + mapTypeId?: string; + mapTypeControl?: boolean; + streetViewControl?: boolean; + fullscreenControl?: boolean; + zoomControl?: boolean; + styles?: Array; + } + + interface MarkerOptions { + position?: { lat: number; lng: number }; + map?: Map; + title?: string; + icon?: any; + } + + interface CircleOptions { + strokeColor?: string; + strokeOpacity?: number; + strokeWeight?: number; + fillColor?: string; + fillOpacity?: number; + map?: Map; + center?: { lat: number; lng: number }; + radius?: number; + } + + const MapTypeId: { + ROADMAP: string; + SATELLITE: string; + HYBRID: string; + TERRAIN: string; + }; + + const SymbolPath: { + CIRCLE: number; + FORWARD_CLOSED_ARROW: number; + FORWARD_OPEN_ARROW: number; + BACKWARD_CLOSED_ARROW: number; + BACKWARD_OPEN_ARROW: number; + }; + } +} + +// Extend the Window interface +interface Window { + google: typeof google; +} \ No newline at end of file