🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance GlobeStore with timeline style management and update GlobePage for dynamic styling
Bill Yang17a2cbdc4e5e
diff --git a/client/src/app/[site]/globe/3d/hooks/useMapbox.ts b/client/src/app/[site]/globe/3d/hooks/useMapbox.tsindex d1bbdc3a5..f171b8a50 100644--- a/client/src/app/[site]/globe/3d/hooks/useMapbox.ts+++ b/client/src/app/[site]/globe/3d/hooks/useMapbox.ts@@ -15,7 +15,7 @@ export function useMapbox(containerRef: React.RefObject<HTMLDivElement | null>,// Customize water/ocean color if the layer existstry {if (mapInstance.getLayer("water")) {- // mapInstance.setPaintProperty("water", "fill-color", "#0a1929");+ mapInstance.setPaintProperty("water", "fill-color", "#0a1929");}} catch (error) {console.warn("Could not set water color:", error);@@ -90,9 +90,14 @@ export function useMapbox(containerRef: React.RefObject<HTMLDivElement | null>,// Wait for map to be idle (fully rendered) before applying custom stylingmapInstance.once("idle", () => {applyCustomStyling(mapInstance);+ // Re-enable mapLoaded so other layers can re-add themselves+ setMapLoaded(true);});};+ // Set mapLoaded to false to trigger other layers to clean up+ setMapLoaded(false);+mapInstance.once("style.load", handleStyleLoad);mapInstance.setStyle(mapStyle);@@ -100,7 +105,8 @@ export function useMapbox(containerRef: React.RefObject<HTMLDivElement | null>,return () => {mapInstance.off("style.load", handleStyleLoad);};- }, [mapStyle, mapLoaded]);+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [mapStyle]); // Only depend on mapStyle, not mapLoadedreturn { map, mapLoaded };}diff --git a/client/src/app/[site]/globe/components/MapStyleSelector.tsx b/client/src/app/[site]/globe/components/MapStyleSelector.tsxindex af62c1320..7470472cb 100644--- a/client/src/app/[site]/globe/components/MapStyleSelector.tsx+++ b/client/src/app/[site]/globe/components/MapStyleSelector.tsx@@ -25,10 +25,16 @@ const MAP_STYLES: MapStyle[] = [];export default function MapStyleSelector() {- const { mapStyle, setMapStyle } = useGlobeStore();+ const { mapStyle, setMapStyle, setTimelineStyle } = useGlobeStore();const currentStyle = MAP_STYLES.find(style => style.url === mapStyle);+ const handleStyleChange = (styleUrl: string) => {+ setMapStyle(styleUrl);+ // Also update timelineStyle so it persists when switching views+ setTimelineStyle(styleUrl);+ };+return (<DropdownMenu><DropdownMenuTrigger@@ -42,7 +48,7 @@ export default function MapStyleSelector() {{MAP_STYLES.map(style => (<DropdownMenuItemkey={style.url}- onClick={() => setMapStyle(style.url)}+ onClick={() => handleStyleChange(style.url)}className={mapStyle === style.url ? "bg-neutral-100 dark:bg-neutral-800" : ""}>{style.name}diff --git a/client/src/app/[site]/globe/globeStore.ts b/client/src/app/[site]/globe/globeStore.tsindex 712e1d284..31e2a8e7c 100644--- a/client/src/app/[site]/globe/globeStore.ts+++ b/client/src/app/[site]/globe/globeStore.ts@@ -9,6 +9,8 @@ interface GlobeStore {setMapMode: (mode: "3D" | "2D") => void;mapStyle: string;setMapStyle: (style: string) => void;+ timelineStyle: string;+ setTimelineStyle: (style: string) => void;}export const useGlobeStore = create<GlobeStore>(set => ({@@ -18,4 +20,6 @@ export const useGlobeStore = create<GlobeStore>(set => ({setMapMode: mode => set({ mapMode: mode }),mapStyle: "mapbox://styles/mapbox/standard",setMapStyle: style => set({ mapStyle: style }),+ timelineStyle: "mapbox://styles/mapbox/standard",+ setTimelineStyle: style => set({ timelineStyle: style }),}));diff --git a/client/src/app/[site]/globe/page.tsx b/client/src/app/[site]/globe/page.tsxindex cc557cfdf..1a5ef8f3d 100644--- a/client/src/app/[site]/globe/page.tsx+++ b/client/src/app/[site]/globe/page.tsx@@ -1,7 +1,7 @@"use client";import "mapbox-gl/dist/mapbox-gl.css";-import { useRef } from "react";+import { useEffect, useRef } from "react";import "./globe.css";import { VisuallyHidden } from "radix-ui";@@ -36,7 +36,22 @@ export default function GlobePage() {// Fetch timeline sessions and update storeuseTimelineSessions();- const { mapView, mapMode } = useGlobeStore();+ const { mapView, mapMode, mapStyle, setMapStyle, timelineStyle, setTimelineStyle } = useGlobeStore();++ // Automatically switch styles based on view+ useEffect(() => {+ if (mapView === "timeline") {+ // Restore timeline style when switching back to timeline view+ if (mapStyle !== timelineStyle) {+ setMapStyle(timelineStyle);+ }+ } else {+ // Force dark-v11 for non-timeline views+ if (mapStyle !== "mapbox://styles/mapbox/dark-v11") {+ setMapStyle("mapbox://styles/mapbox/dark-v11");+ }+ }+ }, [mapView, mapStyle, timelineStyle, setMapStyle]);const { map, mapLoaded } = useMapbox(mapContainer, mapMode === "3D");