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 structure and functionality

Bill Yang5bef3173e9af
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index 3b2c94680..33426b0b4 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -70,12 +70,12 @@ export function Sidebar() {
href={getTabPath("realtime")}
icon={<Earth className="w-4 h-4" />}
/>
- {/* <SidebarLink
+ <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/Map.tsx b/client/src/app/[site]/components/shared/Map.tsx
similarity index 93%
rename from client/src/app/[site]/main/components/sections/Map.tsx
rename to client/src/app/[site]/components/shared/Map.tsx
index 650225a44..62ed072ee 100644
--- a/client/src/app/[site]/main/components/sections/Map.tsx
+++ b/client/src/app/[site]/components/shared/Map.tsx
@@ -8,8 +8,9 @@ import { Layer } from "leaflet";
import { Feature, GeoJsonObject } from "geojson";
import "leaflet/dist/leaflet.css";
import { useSingleCol } from "@/api/analytics/useSingleCol";
-import { addFilter, FilterParameter } from "../../../../../lib/store";
-import { useCountries, useSubdivisions } from "../../../../../lib/geo";
+import { addFilter, FilterParameter } from "../../../../lib/store";
+import { useCountries, useSubdivisions } from "../../../../lib/geo";
+import { useMeasure } from "@uidotdev/usehooks";
interface TooltipContent {
name: string;
@@ -23,7 +24,7 @@ interface TooltipPosition {
y: number;
}
-export function MapComponent() {
+export function MapComponent({ height }: { height: string }) {
const { data: countryData, isLoading: isCountryLoading } = useSingleCol({
parameter: "country",
});
@@ -169,6 +170,10 @@ export function MapComponent() {
const isLoading = isCountryLoading || isSubdivisionLoading;
+ const [ref, { height: resolvedHeight }] = useMeasure();
+
+ const zoom = resolvedHeight ? Math.log2(resolvedHeight / 400) + 1 : 1;
+
return (
<div
onMouseMove={(e) => {
@@ -179,6 +184,10 @@ export function MapComponent() {
});
}
}}
+ style={{
+ height: height,
+ }}
+ ref={ref}
>
{(countriesGeoData || subdivisionsGeoData) && (
<MapContainer
@@ -186,9 +195,10 @@ export function MapComponent() {
attributionControl={false}
zoomControl={false}
center={[40, 3]}
- zoom={1}
+ zoom={zoom}
style={{
- height: "380px",
+ // height: height,
+ height: "100%",
background: "none",
cursor: "default",
outline: "none",
diff --git a/client/src/app/[site]/main/components/sections/Countries.tsx b/client/src/app/[site]/main/components/sections/Countries.tsx
index 993ca919f..1ab482506 100644
--- a/client/src/app/[site]/main/components/sections/Countries.tsx
+++ b/client/src/app/[site]/main/components/sections/Countries.tsx
@@ -13,7 +13,7 @@ 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";
+import { MapComponent } from "../../../components/shared/Map";
type Tab = "countries" | "regions" | "languages" | "cities" | "map";
@@ -154,7 +154,7 @@ export function Countries({ isRealtime = false }: { isRealtime?: boolean }) {
/>
</TabsContent>
<TabsContent value="map">
- <MapComponent />
+ <MapComponent height="380px" />
</TabsContent>
</Tabs>
</CardContent>
diff --git a/client/src/app/[site]/main/page.tsx b/client/src/app/[site]/main/page.tsx
index eca170ff8..ae74a28fd 100644
--- a/client/src/app/[site]/main/page.tsx
+++ b/client/src/app/[site]/main/page.tsx
@@ -6,7 +6,6 @@ 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 { MapComponent } from "./components/sections/Map";
import { Pages } from "./components/sections/Pages";
import { Referrers } from "./components/sections/Referrers";
import { Weekdays } from "./components/sections/Weekdays";
diff --git a/client/src/app/[site]/map/page.tsx b/client/src/app/[site]/map/page.tsx
index 0d5e134c0..8efee6629 100644
--- a/client/src/app/[site]/map/page.tsx
+++ b/client/src/app/[site]/map/page.tsx
@@ -1,3 +1,14 @@
+import { MobileSidebar } from "../../../components/MobileSidebar";
+import { MapComponent } from "../components/shared/Map";
+import { SubHeader } from "../components/SubHeader/SubHeader";
+
export default function MapPage() {
- return <div>MapPage</div>;
+ return (
+ <div className="relative w-full">
+ <div className="p-4">
+ <SubHeader />
+ </div>
+ <MapComponent height="calc(100vh - 45px - 76px)" />
+ </div>
+ );
}
diff --git a/client/src/components/Sessions/SessionsList.tsx b/client/src/components/Sessions/SessionsList.tsx
index eb64e8b72..f7fe34e12 100644
--- a/client/src/components/Sessions/SessionsList.tsx
+++ b/client/src/components/Sessions/SessionsList.tsx
@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef } from "react";
import { useGetSessionsInfinite } from "../../api/analytics/userSessions";
import { SessionCard, SessionCardSkeleton } from "./SessionCard";
+import { Button } from "../ui/button";
export default function SessionsList({ userId }: { userId?: string }) {
// Get sessions data with infinite loading
@@ -22,32 +23,6 @@ export default function SessionsList({ userId }: { userId?: string }) {
// Reference for the scroll container
const containerRef = useRef<HTMLDivElement>(null);
- // Infinite scroll implementation
- useEffect(() => {
- const handleScroll = () => {
- if (!containerRef.current) return;
-
- const { scrollHeight, scrollTop, clientHeight } = containerRef.current;
-
- // Load more when user scrolls to bottom (with a 200px buffer)
- if (
- scrollHeight - scrollTop - clientHeight < 200 &&
- !isFetchingNextPage &&
- hasNextPage
- ) {
- fetchNextPage();
- }
- };
-
- const container = containerRef.current;
- if (container) {
- container.addEventListener("scroll", handleScroll);
- return () => {
- container.removeEventListener("scroll", handleScroll);
- };
- }
- }, [fetchNextPage, hasNextPage, isFetchingNextPage]);
-
if (error)
return (
<div className="text-red-500 p-4">Error: {(error as Error).message}</div>
@@ -78,6 +53,18 @@ export default function SessionsList({ userId }: { userId?: string }) {
<SessionCardSkeleton key="loading-more" />
</div>
)}
+
+ {hasNextPage && (
+ <div className="flex justify-center py-2">
+ <Button
+ onClick={() => fetchNextPage()}
+ className="w-full"
+ variant="success"
+ >
+ Load more
+ </Button>
+ </div>
+ )}
</div>
);
}
diff --git a/client/src/components/ui/card.tsx b/client/src/components/ui/card.tsx
index dda8732c5..bc00a7d76 100644
--- a/client/src/components/ui/card.tsx
+++ b/client/src/components/ui/card.tsx
@@ -1,10 +1,9 @@
"use client";
-import * as React from "react";
import { cn } from "@/lib/utils";
-import { useMeasure } from "@uidotdev/usehooks";
import { Zoomies } from "ldrs/react";
import "ldrs/react/Zoomies.css";
+import * as React from "react";
// Default values shown
const Card = React.forwardRef<
@@ -26,10 +25,8 @@ const CardLoader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => {
- const [ref2, { width }] = useMeasure();
-
return (
- <div ref={ref2} className="mt-[-15px] absolute top-0 left-0 w-full">
+ <div className="mt-[-15px] absolute top-0 left-0 w-full">
<Zoomies
size={1400}
stroke="3"
@@ -107,10 +104,10 @@ CardFooter.displayName = "CardFooter";
export {
Card,
- CardLoader,
- CardHeader,
+ CardContent,
+ CardDescription,
CardFooter,
+ CardHeader,
+ CardLoader,
CardTitle,
- CardDescription,
- CardContent,
};