Skip to content

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

Refactor Sidebar components for improved organization and functionality

Bill Yang27dd59f62a3a
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index 87b3b806d..86ce10ffb 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -16,13 +16,12 @@ import {
User,
Video,
} from "lucide-react";
-import Link from "next/link";
import { usePathname } from "next/navigation";
import { useGetSite } from "../../../../api/admin/sites";
+import { Sidebar as SidebarComponents } from "../../../../components/sidebar/Sidebar";
import { SiteSettings } from "../../../../components/SiteSettings/SiteSettings";
import { authClient } from "../../../../lib/auth";
import { IS_CLOUD } from "../../../../lib/const";
-import { cn } from "../../../../lib/utils";
import { SiteSelector } from "./SiteSelector";
export function Sidebar() {
@@ -44,33 +43,33 @@ export function Sidebar() {
};
return (
- <div className="w-56 bg-neutral-900 border-r border-neutral-800 flex flex-col justify-between h-screen">
+ <div className="w-56 bg-neutral-900 border-r border-neutral-850 flex flex-col h-screen">
<div className="flex flex-col">
<div className="flex flex-col p-3 border-b border-neutral-800">
<SiteSelector />
</div>
- <div className="flex flex-col p-3">
- <div className="text-xs text-neutral-400 mt-0 mb-1 mx-3 font-medium">Web Analytics</div>
- <SidebarLink
+ <div className="flex flex-col p-3 pt-1">
+ <SidebarComponents.SectionHeader>Web Analytics</SidebarComponents.SectionHeader>
+ <SidebarComponents.Item
label="Main"
active={isActiveTab("main")}
href={getTabPath("main")}
icon={<LayoutDashboard className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Realtime"
active={isActiveTab("realtime")}
href={getTabPath("realtime")}
icon={<Earth className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Map"
active={isActiveTab("map")}
href={getTabPath("map")}
icon={<Map className="w-4 h-4" />}
/>
{IS_CLOUD && (
- <SidebarLink
+ <SidebarComponents.Item
label="Pages"
active={isActiveTab("pages")}
href={getTabPath("pages")}
@@ -78,72 +77,72 @@ export function Sidebar() {
/>
)}
{IS_CLOUD && (
- <SidebarLink
+ <SidebarComponents.Item
label="Performance"
active={isActiveTab("performance")}
href={getTabPath("performance")}
icon={<Gauge className="w-4 h-4" />}
/>
)}
- <SidebarLink
+ <SidebarComponents.Item
label="Goals"
active={isActiveTab("goals")}
href={getTabPath("goals")}
icon={<Target weight="bold" />}
/>
- <div className="text-xs text-neutral-400 mt-3 mb-1 mx-3 font-medium">Product Analytics</div>
+ <SidebarComponents.SectionHeader>Product Analytics</SidebarComponents.SectionHeader>
<div className="hidden md:block">
- <SidebarLink
+ <SidebarComponents.Item
label="Replay"
active={isActiveTab("replay")}
href={getTabPath("replay")}
icon={<Video className="w-4 h-4" />}
/>
</div>
- <SidebarLink
+ <SidebarComponents.Item
label="Funnels"
active={isActiveTab("funnels")}
href={getTabPath("funnels")}
icon={<Funnel weight="bold" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Journeys"
active={isActiveTab("journeys")}
href={getTabPath("journeys")}
icon={<Split className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Retention"
active={isActiveTab("retention")}
href={getTabPath("retention")}
icon={<ChartColumnDecreasing className="w-4 h-4" />}
/>
- <div className="text-xs text-neutral-400 mt-3 mb-1 mx-3 font-medium">Behavior</div>
- <SidebarLink
+ <SidebarComponents.SectionHeader>Behavior</SidebarComponents.SectionHeader>
+ <SidebarComponents.Item
label="Sessions"
active={isActiveTab("sessions")}
href={getTabPath("sessions")}
icon={<Rewind className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Users"
active={isActiveTab("users")}
href={getTabPath("users")}
icon={<User className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Events"
active={isActiveTab("events")}
href={getTabPath("events")}
icon={<MousePointerClick className="w-4 h-4" />}
/>
- <SidebarLink
+ <SidebarComponents.Item
label="Errors"
active={isActiveTab("errors")}
href={getTabPath("errors")}
icon={<AlertTriangle className="w-4 h-4" />}
/>
- {/* <SidebarLink
+ {/* <SidebarComponents.Item
label="Reports"
active={isActiveTab("reports")}
href={getTabPath("reports")}
@@ -169,32 +168,3 @@ export function Sidebar() {
</div>
);
}
-
-// Sidebar Link component
-function SidebarLink({
- label,
- active = false,
- href,
- icon,
-}: {
- label: string;
- active?: boolean;
- href: string;
- icon?: React.ReactNode;
-}) {
- return (
- <Link href={href} className="focus:outline-none">
- <div
- className={cn(
- "px-3 py-2 rounded-lg transition-colors w-full",
- active ? "bg-neutral-800 text-white" : "text-neutral-200 hover:text-white hover:bg-neutral-800/50"
- )}
- >
- <div className="flex items-center gap-2">
- {icon}
- <span className="text-sm">{label}</span>
- </div>
- </div>
- </Link>
- );
-}
diff --git a/client/src/app/settings/components/MobileSidebar.tsx b/client/src/app/settings/components/MobileSidebar.tsx
index 3b42d2668..a7726d59d 100644
--- a/client/src/app/settings/components/MobileSidebar.tsx
+++ b/client/src/app/settings/components/MobileSidebar.tsx
@@ -6,7 +6,7 @@ import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "../.
import { Menu } from "lucide-react";
import { VisuallyHidden } from "radix-ui";
import { AppSidebar } from "../../../components/AppSidebar";
-import { Sidebar } from "./SIdebar";
+import { SettingsSidebar } from "./SettingsSidebar";
export function MobileSidebar() {
return (
@@ -24,7 +24,7 @@ export function MobileSidebar() {
</VisuallyHidden.Root>
<SheetContent side="left" className="p-0 w-[240px] flex gap-0" showClose={false}>
<AppSidebar />
- <Sidebar />
+ <SettingsSidebar />
</SheetContent>
</Sheet>
</div>
diff --git a/client/src/app/settings/components/SIdebar.tsx b/client/src/app/settings/components/SIdebar.tsx
deleted file mode 100644
index 50aa25ea7..000000000
--- a/client/src/app/settings/components/SIdebar.tsx
+++ /dev/null
@@ -1,64 +0,0 @@
-"use client";
-import Link from "next/link";
-import { usePathname } from "next/navigation";
-import { Building2, CreditCard, UserCircle } from "lucide-react";
-import { cn } from "../../../lib/utils";
-
-export function Sidebar() {
- const pathname = usePathname();
-
- return (
- <div className="w-56 bg-neutral-900 border-r border-neutral-800 flex flex-col justify-between">
- <div className="flex flex-col p-3">
- <div className="text-base text-neutral-100 mt-2 mb-4 mx-1 font-medium">Settings</div>
- <SidebarLink
- label="Account"
- active={pathname.startsWith("/settings/account")}
- href={"/settings/account"}
- icon={<UserCircle className="w-4 h-4" />}
- />
- <SidebarLink
- label="Organization"
- active={pathname.startsWith("/settings/organization/members")}
- href={"/settings/organization"}
- icon={<Building2 className="w-4 h-4" />}
- />
- <SidebarLink
- label="Subscription"
- active={pathname.startsWith("/settings/organization/subscription")}
- href={"/settings/organization/subscription"}
- icon={<CreditCard className="w-4 h-4" />}
- />
- </div>
- </div>
- );
-}
-
-// Sidebar Link component
-function SidebarLink({
- label,
- active = false,
- href,
- icon,
-}: {
- label: string;
- active?: boolean;
- href: string;
- icon?: React.ReactNode;
-}) {
- return (
- <Link href={href} className="focus:outline-none">
- <div
- className={cn(
- "px-3 py-2 rounded-lg transition-colors w-full",
- active ? "bg-neutral-800 text-white" : "text-neutral-200 hover:text-white hover:bg-neutral-800/50"
- )}
- >
- <div className="flex items-center gap-2">
- {icon}
- <span className="text-sm">{label}</span>
- </div>
- </div>
- </Link>
- );
-}
diff --git a/client/src/app/settings/components/SettingsSidebar.tsx b/client/src/app/settings/components/SettingsSidebar.tsx
new file mode 100644
index 000000000..f10f7bf9d
--- /dev/null
+++ b/client/src/app/settings/components/SettingsSidebar.tsx
@@ -0,0 +1,34 @@
+"use client";
+import { Building2, CreditCard, UserCircle } from "lucide-react";
+import { usePathname } from "next/navigation";
+import { Sidebar } from "../../../components/sidebar/Sidebar";
+
+export function SettingsSidebar() {
+ const pathname = usePathname();
+
+ return (
+ <Sidebar.Root>
+ <Sidebar.Title>Settings</Sidebar.Title>
+ <Sidebar.Items>
+ <Sidebar.Item
+ label="Account"
+ active={pathname.startsWith("/settings/account")}
+ href={"/settings/account"}
+ icon={<UserCircle className="w-4 h-4" />}
+ />
+ <Sidebar.Item
+ label="Organization"
+ active={pathname.startsWith("/settings/organization/members")}
+ href={"/settings/organization"}
+ icon={<Building2 className="w-4 h-4" />}
+ />
+ <Sidebar.Item
+ label="Subscription"
+ active={pathname.startsWith("/settings/organization/subscription")}
+ href={"/settings/organization/subscription"}
+ icon={<CreditCard className="w-4 h-4" />}
+ />
+ </Sidebar.Items>
+ </Sidebar.Root>
+ );
+}
diff --git a/client/src/app/settings/layout.tsx b/client/src/app/settings/layout.tsx
index d10d3dae2..d34c042b7 100644
--- a/client/src/app/settings/layout.tsx
+++ b/client/src/app/settings/layout.tsx
@@ -4,7 +4,7 @@ import { useWindowSize } from "@uidotdev/usehooks";
import { AppSidebar } from "../../components/AppSidebar";
import { StandardPage } from "../../components/StandardPage";
import { MobileSidebar } from "./components/MobileSidebar";
-import { Sidebar } from "./components/SIdebar";
+import { SettingsSidebar } from "./components/SettingsSidebar";
export default function SettingsLayout({ children }: { children: React.ReactNode }) {
const { width } = useWindowSize();
@@ -21,7 +21,7 @@ export default function SettingsLayout({ children }: { children: React.ReactNode
return (
<div className="flex h-full">
<AppSidebar />
- <Sidebar />
+ <SettingsSidebar />
<StandardPage showSidebar={false}>
<div className="flex-1 overflow-auto mt-4">{children}</div>
</StandardPage>
diff --git a/client/src/app/uptime/layout.tsx b/client/src/app/uptime/layout.tsx
index e62c032dd..63d701e10 100644
--- a/client/src/app/uptime/layout.tsx
+++ b/client/src/app/uptime/layout.tsx
@@ -4,7 +4,7 @@ import { useWindowSize } from "@uidotdev/usehooks";
import { AppSidebar } from "../../components/AppSidebar";
import { MobileSidebar } from "./monitors/components/Sidebar/MobileSidebar";
import { StandardPage } from "../../components/StandardPage";
-import { Sidebar } from "./monitors/components/Sidebar/Sidebar";
+import { UptimeSidebar } from "./monitors/components/Sidebar/UptimeSidebar";
export default function UptimeLayout({ children }: { children: React.ReactNode }) {
const { width } = useWindowSize();
@@ -21,7 +21,7 @@ export default function UptimeLayout({ children }: { children: React.ReactNode }
return (
<div className="flex h-full">
<AppSidebar />
- <Sidebar />
+ <UptimeSidebar />
<StandardPage showSidebar={false}>
<div className="flex-1 overflow-auto mt-4">{children}</div>
</StandardPage>
diff --git a/client/src/app/uptime/monitors/components/Sidebar/MobileSidebar.tsx b/client/src/app/uptime/monitors/components/Sidebar/MobileSidebar.tsx
index ba7efee24..4bffe90f5 100644
--- a/client/src/app/uptime/monitors/components/Sidebar/MobileSidebar.tsx
+++ b/client/src/app/uptime/monitors/components/Sidebar/MobileSidebar.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Sidebar } from "./Sidebar";
+import { UptimeSidebar } from "./UptimeSidebar";
import { Menu } from "lucide-react";
import { VisuallyHidden } from "radix-ui";
@@ -24,7 +24,7 @@ export function MobileSidebar() {
</VisuallyHidden.Root>
<SheetContent side="left" className="p-0 w-[240px] flex gap-0" showClose={false}>
<AppSidebar />
- <Sidebar />
+ <UptimeSidebar />
</SheetContent>
</Sheet>
</div>
diff --git a/client/src/app/uptime/monitors/components/Sidebar/Sidebar.tsx b/client/src/app/uptime/monitors/components/Sidebar/Sidebar.tsx
deleted file mode 100644
index 82d4410ee..000000000
--- a/client/src/app/uptime/monitors/components/Sidebar/Sidebar.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-"use client";
-import Link from "next/link";
-import { usePathname } from "next/navigation";
-import { cn } from "../../../../../lib/utils";
-import { Activity, AlertCircle, Plug2, Globe } from "lucide-react";
-
-export function Sidebar() {
- const pathname = usePathname();
-
- return (
- <div className="w-56 bg-neutral-900 border-r border-neutral-800 flex flex-col justify-between">
- <div className="flex flex-col p-3">
- <div className="text-base text-neutral-100 mt-2 mb-4 mx-1 font-medium">Uptime</div>
- <SidebarLink
- label="Monitors"
- active={pathname.startsWith("/uptime/monitors")}
- href={"/uptime/monitors"}
- icon={<Activity className="w-4 h-4" />}
- />
- <SidebarLink
- label="Incidents"
- active={pathname.startsWith("/uptime/incidents")}
- href={"/uptime/incidents"}
- icon={<AlertCircle className="w-4 h-4" />}
- />
- <SidebarLink
- label="Notifications"
- active={pathname.startsWith("/uptime/notifications")}
- href={"/uptime/notifications"}
- icon={<Plug2 className="w-4 h-4" />}
- />
- <SidebarLink
- label="Status Page"
- active={pathname.startsWith("/uptime/status-page")}
- href={"/uptime/status-page"}
- icon={<Globe className="w-4 h-4" />}
- />
- </div>
- </div>
- );
-}
-
-// Sidebar Link component
-function SidebarLink({
- label,
- active = false,
- href,
- icon,
-}: {
- label: string;
- active?: boolean;
- href: string;
- icon?: React.ReactNode;
-}) {
- return (
- <Link href={href} className="focus:outline-none">
- <div
- className={cn(
- "px-3 py-2 rounded-lg transition-colors w-full",
- active ? "bg-neutral-800 text-white" : "text-neutral-200 hover:text-white hover:bg-neutral-800/50"
- )}
- >
- <div className="flex items-center gap-2">
- {icon}
- <span className="text-sm">{label}</span>
- </div>
- </div>
- </Link>
- );
-}
diff --git a/client/src/app/uptime/monitors/components/Sidebar/UptimeSidebar.tsx b/client/src/app/uptime/monitors/components/Sidebar/UptimeSidebar.tsx
new file mode 100644
index 000000000..a27d6ffff
--- /dev/null
+++ b/client/src/app/uptime/monitors/components/Sidebar/UptimeSidebar.tsx
@@ -0,0 +1,40 @@
+"use client";
+import { Activity, AlertCircle, Plug2, Globe } from "lucide-react";
+import { usePathname } from "next/navigation";
+import { Sidebar } from "../../../../../components/sidebar/Sidebar";
+
+export function UptimeSidebar() {
+ const pathname = usePathname();
+
+ return (
+ <Sidebar.Root>
+ <Sidebar.Title>Uptime</Sidebar.Title>
+ <Sidebar.Items>
+ <Sidebar.Item
+ label="Monitors"
+ active={pathname.startsWith("/uptime/monitors")}
+ href={"/uptime/monitors"}
+ icon={<Activity className="w-4 h-4" />}
+ />
+ <Sidebar.Item
+ label="Incidents"
+ active={pathname.startsWith("/uptime/incidents")}
+ href={"/uptime/incidents"}
+ icon={<AlertCircle className="w-4 h-4" />}
+ />
+ <Sidebar.Item
+ label="Notifications"
+ active={pathname.startsWith("/uptime/notifications")}
+ href={"/uptime/notifications"}
+ icon={<Plug2 className="w-4 h-4" />}
+ />
+ <Sidebar.Item
+ label="Status Page"
+ active={pathname.startsWith("/uptime/status-page")}
+ href={"/uptime/status-page"}
+ icon={<Globe className="w-4 h-4" />}
+ />
+ </Sidebar.Items>
+ </Sidebar.Root>
+ );
+}
diff --git a/client/src/components/AppSidebar.tsx b/client/src/components/AppSidebar.tsx
index 2597ca49f..02b5d6868 100644
--- a/client/src/components/AppSidebar.tsx
+++ b/client/src/components/AppSidebar.tsx
@@ -5,7 +5,6 @@ import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useState } from "react";
-import { IS_CLOUD } from "../lib/const";
import { cn } from "../lib/utils";
export function AppSidebar() {
@@ -15,7 +14,7 @@ export function AppSidebar() {
return (
<div
className={cn(
- "flex flex-col items-start justify-between h-screen p-2 py-3 bg-neutral-900 border-r border-neutral-800 gap-3 transition-all duration-1s00",
+ "flex flex-col items-start justify-between h-screen p-2 py-3 bg-neutral-900 border-r border-neutral-850 gap-3 transition-all duration-1s00",
isExpanded ? "w-44" : "w-[45px]"
)}
onMouseEnter={() => setIsExpanded(true)}
diff --git a/client/src/components/SiteCard.tsx b/client/src/components/SiteCard.tsx
index ded5a63d1..cc2d279ed 100644
--- a/client/src/components/SiteCard.tsx
+++ b/client/src/components/SiteCard.tsx
@@ -60,13 +60,12 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
const hasData = (overviewData?.data?.sessions || 0) > 0;
// Show skeleton when loading or not yet in view, but not if we've already loaded data previously
- const showSkeleton =
- (isLoading || isOverviewLoading || !isInView) && !hasLoadedData.current;
+ const showSkeleton = (isLoading || isOverviewLoading || !isInView) && !hasLoadedData.current;
return (
<div
ref={ref}
- className="flex flex-col rounded-lg bg-neutral-900/70 p-4 border border-neutral-800 shadow-lg hover:shadow-xl hover:border-neutral-700 transition-all duration-300 hover:translate-y-[-2px]"
+ className="flex flex-col rounded-lg bg-neutral-900/70 p-4 border border-neutral-850 shadow-lg hover:shadow-xl hover:border-neutral-800 transition-all duration-300 hover:translate-y-[-2px]"
>
{showSkeleton ? (
<>
@@ -100,14 +99,9 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
) : (
<>
<div className="flex justify-between items-center">
- <Link
- href={`/${siteId}`}
- className="group flex gap-3 items-center duration-200"
- >
+ <Link href={`/${siteId}`} className="group flex gap-3 items-center duration-200">
<Favicon domain={domain} className="w-6 h-6" />
- <span className="text-lg font-medium truncate group-hover:underline transition-all">
- {domain}
- </span>
+ <span className="text-lg font-medium truncate group-hover:underline transition-all">{domain}</span>
</Link>
</div>
@@ -115,9 +109,7 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
<SiteSessionChart data={data?.data ?? []} height={110} />
{!hasData && (
<div className="absolute inset-0 flex items-center justify-center bg-neutral-900/70 backdrop-blur-sm">
- <span className="text-sm text-neutral-400">
- No data available
- </span>
+ <span className="text-sm text-neutral-400">No data available</span>
</div>
)}
</div>
@@ -125,32 +117,22 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
<div className="grid grid-cols-3 gap-2 mt-2">
<div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2 hover:bg-neutral-800 transition-colors">
<div className="text-xs text-neutral-400">Sessions</div>
- <div className="font-semibold">
- {overviewData?.data?.sessions?.toLocaleString() || "0"}
- </div>
+ <div className="font-semibold">{overviewData?.data?.sessions?.toLocaleString() || "0"}</div>
</div>
<div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2 hover:bg-neutral-800 transition-colors">
<div className="text-xs text-neutral-400">Users</div>
- <div className="font-semibold">
- {overviewData?.data?.users?.toLocaleString() || "0"}
- </div>
+ <div className="font-semibold">{overviewData?.data?.users?.toLocaleString() || "0"}</div>
</div>
- <Link
- href={`/${siteId}`}
- className="flex items-center justify-center"
- >
+ <Link href={`/${siteId}`} className="flex items-center justify-center">
<Button
variant="outline"
size="sm"
className="w-full h-full border-neutral-700 bg-neutral-800/50 hover:bg-neutral-800 hover:text-blue-400 transition-all"
>
<span className="mr-1">View</span>
- <ArrowRight
- size={14}
- className="transition-transform group-hover:translate-x-0.5"
- />
+ <ArrowRight size={14} className="transition-transform group-hover:translate-x-0.5" />
</Button>
</Link>
</div>
diff --git a/client/src/components/sidebar/Sidebar.tsx b/client/src/components/sidebar/Sidebar.tsx
new file mode 100644
index 000000000..986233ff2
--- /dev/null
+++ b/client/src/components/sidebar/Sidebar.tsx
@@ -0,0 +1,54 @@
+"use client";
+import Link from "next/link";
+import { cn } from "../../lib/utils";
+
+function Root({ children }: { children: React.ReactNode }) {
+ return <div className="w-56 bg-neutral-900 border-r border-neutral-850 flex flex-col">{children}</div>;
+}
+
+function Title({ children }: { children: React.ReactNode }) {
+ return (
+ <div className="flex flex-col p-3 pt-4 border-b border-neutral-800">
+ <div className="text-base text-neutral-100 mx-1 font-medium">{children}</div>
+ </div>
+ );
+}
+
+function SectionHeader({ children }: { children: React.ReactNode }) {
+ return <div className="text-xs text-neutral-400 mt-3 mb-1 mx-3 font-medium">{children}</div>;
+}
+
+function Items({ children }: { children: React.ReactNode }) {
+ return <div className="flex flex-col p-3">{children}</div>;
+}
+
+// Sidebar Link component
+function Item({
+ label,
+ active = false,
+ href,
+ icon,
+}: {
+ label: string;
+ active?: boolean;
+ href: string;
+ icon?: React.ReactNode;
+}) {
+ return (
+ <Link href={href} className="focus:outline-none">
+ <div
+ className={cn(
+ "px-3 py-2 rounded-lg transition-colors w-full",
+ active ? "bg-neutral-800 text-white" : "text-neutral-200 hover:text-white hover:bg-neutral-800/50"
+ )}
+ >
+ <div className="flex items-center gap-2">
+ {icon}
+ <span className="text-sm">{label}</span>
+ </div>
+ </div>
+ </Link>
+ );
+}
+
+export const Sidebar = { Root, Title, Item, Items, SectionHeader };