🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance GlobePage with error handling for Mapbox token and update Sidebar component
Bill Yang95e9a0a73052
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsxindex 1a6c30a3f..e898a074c 100644--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx@@ -2,14 +2,11 @@import {AlertTriangle,ChartColumnDecreasing,- Earth,File,Funnel,Gauge,- Globe,Globe2,LayoutDashboard,- Map,MousePointerClick,Rewind,Settings,@@ -66,12 +63,14 @@ function SidebarContent() {href={getTabPath("realtime")}icon={<Earth className="w-4 h-4" />}/> */}- {/* <SidebarComponents.Item- label="Map"- active={isActiveTab("map")}- href={getTabPath("map")}- icon={<Map className="w-4 h-4" />}- /> */}+ {/* {!IS_CLOUD && (+ <SidebarComponents.Item+ label="Map"+ active={isActiveTab("map")}+ href={getTabPath("map")}+ icon={<Map className="w-4 h-4" />}+ />+ )} */}<SidebarComponents.Itemlabel="Globe"active={isActiveTab("globe")}diff --git a/client/src/app/[site]/globe/hooks/useMapbox.ts b/client/src/app/[site]/globe/hooks/useMapbox.tsindex c7525adb8..bcb833475 100644--- a/client/src/app/[site]/globe/hooks/useMapbox.ts+++ b/client/src/app/[site]/globe/hooks/useMapbox.ts@@ -6,7 +6,9 @@ export function useMapbox(containerRef: React.RefObject<HTMLDivElement | null>)const [mapLoaded, setMapLoaded] = useState(false);useEffect(() => {- if (!containerRef.current) return;+ if (!containerRef.current || !process.env.NEXT_PUBLIC_MAPBOX_TOKEN) {+ return;+ }mapboxgl.accessToken = process.env.NEXT_PUBLIC_MAPBOX_TOKEN || "";diff --git a/client/src/app/[site]/globe/page.tsx b/client/src/app/[site]/globe/page.tsxindex ba144c415..af75f8d74 100644--- a/client/src/app/[site]/globe/page.tsx+++ b/client/src/app/[site]/globe/page.tsx@@ -20,6 +20,7 @@ import { processCountryData, processSubdivisionData } from "./utils/processData"import { useGetSessionLocations } from "../../../api/analytics/useGetSessionLocations";import { GlobeSessions } from "./components/GlobeSessions";import { useGlobeStore } from "./globeStore";+import { NothingFound } from "../../../components/NothingFound";export default function GlobePage() {useSetPageTitle("Rybbit · Globe");@@ -81,10 +82,33 @@ export default function GlobePage() {<SubHeader /></div><div className="absolute top-0 left-0 right-0 bottom-0 z-10">- <div- ref={mapContainer}- className="w-full h-full [&_.mapboxgl-ctrl-bottom-left]:!hidden [&_.mapboxgl-ctrl-logo]:!hidden"- />+ {process.env.NEXT_PUBLIC_MAPBOX_TOKEN ? (+ <div+ ref={mapContainer}+ className="w-full h-full [&_.mapboxgl-ctrl-bottom-left]:!hidden [&_.mapboxgl-ctrl-logo]:!hidden"+ />+ ) : (+ <div className="w-full h-full flex items-center justify-center">+ <NothingFound+ title="Mapbox access token not found"+ description={+ <p className="text-sm max-w-[600px] text-center">+ Please set the <code>NEXT_PUBLIC_MAPBOX_TOKEN</code> environment variable and rebuild all+ containers. To get a Mapbox token, please visit{" "}+ <a+ href="https://docs.mapbox.com/help/dive-deeper/access-tokens/"+ target="_blank"+ rel="noopener noreferrer"+ className="text-blue-400 hover:underline"+ >+ Mapbox+ </a>{" "}+ and create an account.+ </p>+ }+ />+ </div>+ )}<div className="absolute bottom-0 left-4 z-99999"><MapViewSelector /></div>diff --git a/client/src/components/NothingFound.tsx b/client/src/components/NothingFound.tsxindex 5b9520716..1aae7c4e8 100644--- a/client/src/components/NothingFound.tsx+++ b/client/src/components/NothingFound.tsx@@ -5,7 +5,7 @@ export function NothingFound({icon,}: {title: string;- description?: string;+ description?: React.ReactNode;action?: React.ReactNode;icon?: React.ReactNode;}) {