Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor Sidebar and Map components for improved clarity and functionality

Bill Yang58d501f8a344
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index d967f969e..421757af6 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -2,21 +2,21 @@
import { Funnel } from "@phosphor-icons/react/dist/ssr";
import {
ChartBarDecreasing,
- Globe,
+ Earth,
LayoutDashboard,
LayoutGrid,
- Radio,
Rewind,
Settings,
User,
+ Map,
} from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useGetSite } from "../../../../api/admin/sites";
import { SiteSettings } from "../../../../components/SiteSettings/SiteSettings";
+import { authClient } from "../../../../lib/auth";
import LiveUserCount from "./LiveUserCount";
import { SiteSelector } from "./SiteSelector";
-import { authClient } from "../../../../lib/auth";
export function Sidebar() {
const session = authClient.useSession();
@@ -67,8 +67,14 @@ export function Sidebar() {
label="Realtime"
active={isActiveTab("realtime")}
href={getTabPath("realtime")}
- icon={<Globe className="w-4 h-4" />}
+ icon={<Earth className="w-4 h-4" />}
/>
+ {/* <SidebarLink
+ label="Map"
+ active={isActiveTab("map")}
+ href={getTabPath("map")}
+ icon={<Map className="w-4 h-4" />}
+ /> */}
<SidebarLink
label="Retention"
active={isActiveTab("retention")}
diff --git a/client/src/app/[site]/main/components/sections/Countries.tsx b/client/src/app/[site]/main/components/sections/Countries.tsx
index 683204246..9c575982e 100644
--- a/client/src/app/[site]/main/components/sections/Countries.tsx
+++ b/client/src/app/[site]/main/components/sections/Countries.tsx
@@ -13,8 +13,9 @@ import { StandardSection } from "../../../components/shared/StandardSection/Stan
import { CountryFlag } from "../../../components/shared/icons/CountryFlag";
import { useSubdivisions } from "../../../../../lib/geo";
import { StandardSectionRealtime } from "../../../components/shared/StandardSection/StandardSectionRealtime";
+import { MapComponent } from "./Map";
-type Tab = "countries" | "regions" | "languages";
+type Tab = "countries" | "regions" | "languages" | "cities" | "map";
const regionNamesInEnglish = new Intl.DisplayNames(["en"], { type: "region" });
const languageNamesInEnglish = new Intl.DisplayNames(["en"], {
@@ -66,6 +67,7 @@ export function Countries({ isRealtime = false }: { isRealtime?: boolean }) {
<TabsTrigger value="regions">Regions</TabsTrigger>
<TabsTrigger value="cities">Cities</TabsTrigger>
<TabsTrigger value="languages">Languages</TabsTrigger>
+ <TabsTrigger value="map">Map</TabsTrigger>
</TabsList>
<TabsContent value="countries">
<ComponentToUse
@@ -151,6 +153,9 @@ export function Countries({ isRealtime = false }: { isRealtime?: boolean }) {
)}
/>
</TabsContent>
+ <TabsContent value="map">
+ <MapComponent />
+ </TabsContent>
</Tabs>
</CardContent>
</Card>
diff --git a/client/src/app/[site]/main/components/sections/Map.tsx b/client/src/app/[site]/main/components/sections/Map.tsx
index f41a9d361..f633038dd 100644
--- a/client/src/app/[site]/main/components/sections/Map.tsx
+++ b/client/src/app/[site]/main/components/sections/Map.tsx
@@ -30,7 +30,7 @@ interface TooltipPosition {
y: number;
}
-export function Map() {
+export function MapComponent() {
const { data: countryData, isLoading: isCountryLoading } = useSingleCol({
parameter: "country",
});
@@ -177,91 +177,85 @@ export function Map() {
const isLoading = isCountryLoading || isSubdivisionLoading;
return (
- <Card>
- {isLoading && <CardLoader />}
- <CardHeader>
- <CardTitle>Map</CardTitle>
- </CardHeader>
- <CardContent
- onMouseMove={(e) => {
- if (tooltipContent) {
- setTooltipPosition({
- x: e.clientX,
- y: e.clientY,
- });
- }
- }}
- >
- {(countriesGeoData || subdivisionsGeoData) && (
- <MapContainer
- preferCanvas={true}
- attributionControl={false}
- zoomControl={false}
- center={[40, 3]}
- zoom={1}
- style={{
- height: "400px",
- background: "none",
- cursor: "default",
- outline: "none",
- zIndex: "1",
- }}
- >
- <MapEventHandler />
- {mapView === "subdivisions" && subdivisionsGeoData && (
- <GeoJSON
- key={`subdivisions-${dataVersion}`}
- data={subdivisionsGeoData as GeoJsonObject}
- style={handleStyle}
- onEachFeature={handleEachFeature}
- />
- )}
- {mapView === "countries" && countriesGeoData && (
- <GeoJSON
- key={`countries-${dataVersion}`}
- data={countriesGeoData as GeoJsonObject}
- style={handleStyle}
- onEachFeature={handleEachFeature}
- />
- )}
- </MapContainer>
- )}
- {tooltipContent && (
- <div
- className="fixed z-50 bg-neutral-1000 text-white rounded-md p-2 shadow-lg text-sm pointer-events-none"
- style={{
- left: tooltipPosition.x,
- top: tooltipPosition.y - 10,
- transform: "translate(-50%, -100%)",
- }}
- >
- <div className="font-sm flex items-center gap-1">
- {mapView === "countries" &&
- tooltipContent.code &&
- CountryFlags[tooltipContent.code as keyof typeof CountryFlags]
- ? React.createElement(
- CountryFlags[
- tooltipContent.code as keyof typeof CountryFlags
- ],
- {
- title: tooltipContent.name,
- className: "w-4",
- }
- )
- : null}
- {tooltipContent.name}
- </div>
- <div>
- <span className="font-bold text-accent-400">
- {tooltipContent.count.toLocaleString()}
- </span>{" "}
- <span className="text-neutral-300">
- ({tooltipContent.percentage.toFixed(1)}%) sessions
- </span>
- </div>
+ <div
+ onMouseMove={(e) => {
+ if (tooltipContent) {
+ setTooltipPosition({
+ x: e.clientX,
+ y: e.clientY,
+ });
+ }
+ }}
+ >
+ {(countriesGeoData || subdivisionsGeoData) && (
+ <MapContainer
+ preferCanvas={true}
+ attributionControl={false}
+ zoomControl={false}
+ center={[40, 3]}
+ zoom={1}
+ style={{
+ height: "380px",
+ background: "none",
+ cursor: "default",
+ outline: "none",
+ zIndex: "1",
+ }}
+ >
+ <MapEventHandler />
+ {mapView === "subdivisions" && subdivisionsGeoData && (
+ <GeoJSON
+ key={`subdivisions-${dataVersion}`}
+ data={subdivisionsGeoData as GeoJsonObject}
+ style={handleStyle}
+ onEachFeature={handleEachFeature}
+ />
+ )}
+ {mapView === "countries" && countriesGeoData && (
+ <GeoJSON
+ key={`countries-${dataVersion}`}
+ data={countriesGeoData as GeoJsonObject}
+ style={handleStyle}
+ onEachFeature={handleEachFeature}
+ />
+ )}
+ </MapContainer>
+ )}
+ {tooltipContent && (
+ <div
+ className="fixed z-50 bg-neutral-1000 text-white rounded-md p-2 shadow-lg text-sm pointer-events-none"
+ style={{
+ left: tooltipPosition.x,
+ top: tooltipPosition.y - 10,
+ transform: "translate(-50%, -100%)",
+ }}
+ >
+ <div className="font-sm flex items-center gap-1">
+ {mapView === "countries" &&
+ tooltipContent.code &&
+ CountryFlags[tooltipContent.code as keyof typeof CountryFlags]
+ ? React.createElement(
+ CountryFlags[
+ tooltipContent.code as keyof typeof CountryFlags
+ ],
+ {
+ title: tooltipContent.name,
+ className: "w-4",
+ }
+ )
+ : null}
+ {tooltipContent.name}
</div>
- )}
- </CardContent>
- </Card>
+ <div>
+ <span className="font-bold text-accent-400">
+ {tooltipContent.count.toLocaleString()}
+ </span>{" "}
+ <span className="text-neutral-300">
+ ({tooltipContent.percentage.toFixed(1)}%) sessions
+ </span>
+ </div>
+ </div>
+ )}
+ </div>
);
}
diff --git a/client/src/app/[site]/main/page.tsx b/client/src/app/[site]/main/page.tsx
index ff8e3244a..89bce3c5f 100644
--- a/client/src/app/[site]/main/page.tsx
+++ b/client/src/app/[site]/main/page.tsx
@@ -6,7 +6,7 @@ import { MainSection } from "./components/MainSection/MainSection";
import { Countries } from "./components/sections/Countries";
import { Devices } from "./components/sections/Devices";
import { Events } from "./components/sections/Events";
-import { Map } from "./components/sections/Map";
+import { MapComponent } from "./components/sections/Map";
import { Pages } from "./components/sections/Pages";
import { Referrers } from "./components/sections/Referrers";
import { Weekdays } from "./components/sections/Weekdays";
@@ -39,7 +39,6 @@ function MainPageContent() {
<Countries />
<Events />
<Weekdays />
- <Map />
</div>
</div>
);
diff --git a/client/src/app/[site]/map/page.tsx b/client/src/app/[site]/map/page.tsx
new file mode 100644
index 000000000..0d5e134c0
--- /dev/null
+++ b/client/src/app/[site]/map/page.tsx
@@ -0,0 +1,3 @@
+export default function MapPage() {
+ return <div>MapPage</div>;
+}