Skip to content

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

Convert SiteSelector from dropdown menu to popover, enhancing UI with improved site display and new site creation functionality. Integrated session count display, added scrollable container for better UX, and updated loading states. Refactored related components for consistency and responsiveness.

Bill Yangf28eb37a35e8
diff --git a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
index 06d850c2c..c19db40be 100644
--- a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
+++ b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
@@ -1,17 +1,18 @@
-import { Check } from "lucide-react";
+import { Check, ChevronDown, Plus } from "lucide-react";
import { usePathname, useRouter } from "next/navigation";
import { useGetSite, useGetSitesFromOrg } from "../../../../api/admin/sites";
import { Favicon } from "../../../../components/Favicon";
import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "../../../../components/ui/dropdown-menu";
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "../../../../components/ui/popover";
+import { Button } from "../../../../components/ui/button";
import { authClient } from "../../../../lib/auth";
import { resetStore, useStore } from "../../../../lib/store";
import { userStore } from "../../../../lib/userStore";
-import { cn } from "../../../../lib/utils";
+import { cn, formatter } from "../../../../lib/utils";
+import { AddSite } from "../../../components/AddSite";
function SiteSelectorContent() {
const { data: activeOrganization } = authClient.useActiveOrganization();
@@ -23,45 +24,68 @@ function SiteSelectorContent() {
const currentSiteId = Number(pathname.split("/")[1]);
return (
- <DropdownMenuContent align="start">
- {sites?.sites
- ? sites.sites.map((site) => {
- const isSelected = site.siteId === currentSiteId;
- return (
- <DropdownMenuItem
- key={site.siteId}
- onClick={() => {
- if (isSelected) return;
- resetStore();
- setSite(site.siteId.toString());
- router.push(`/${site.siteId}`);
- }}
- className={cn(
- "flex items-center justify-between",
- isSelected && "bg-neutral-800"
- )}
+ <PopoverContent align="start" className="w-80 p-2">
+ <div className="max-h-96 overflow-y-auto">
+ {sites?.sites
+ ? sites.sites.map((site) => {
+ const isSelected = site.siteId === currentSiteId;
+ return (
+ <div
+ key={site.siteId}
+ onClick={() => {
+ if (isSelected) return;
+ resetStore();
+ setSite(site.siteId.toString());
+ router.push(`/${site.siteId}`);
+ }}
+ className={cn(
+ "flex items-center justify-between p-2 cursor-pointer hover:bg-neutral-800/50 transition-colors rounded-md border-b border-neutral-800 last:border-b-0",
+ isSelected && "bg-neutral-800"
+ )}
+ >
+ <div className="flex items-center gap-3 flex-1 min-w-0">
+ <Favicon
+ domain={site.domain}
+ className="w-4 h-4 flex-shrink-0"
+ />
+ <div className="text-sm text-white truncate">
+ {site.domain}
+ </div>
+ </div>
+ <div className="flex items-center gap-3">
+ <div className="text-xs text-neutral-300 whitespace-nowrap">
+ {formatter(site.sessionsLast24Hours)} sessions (24h)
+ </div>
+ </div>
+ </div>
+ );
+ })
+ : Array.from({ length: 3 }).map((_, index) => (
+ <div
+ key={`skeleton-${index}`}
+ className="flex items-center justify-between p-2 animate-pulse rounded-md border-b border-neutral-800 last:border-b-0"
>
- <div className="flex items-center gap-2">
- <Favicon domain={site.domain} className="w-4 h-4" />
- <span>{site.domain}</span>
+ <div className="flex items-center gap-3 flex-1">
+ <div className="w-4 h-4 bg-neutral-700 rounded flex-shrink-0"></div>
+ <div className="h-4 bg-neutral-700 rounded w-32"></div>
</div>
- {isSelected && <Check size={16} />}
- </DropdownMenuItem>
- );
- })
- : Array.from({ length: 3 }).map((_, index) => (
- <DropdownMenuItem
- key={`skeleton-${index}`}
- className="flex items-center justify-between animate-pulse cursor-default"
- onClick={(e) => e.preventDefault()}
- >
- <div className="flex items-center gap-2">
- <div className="w-4 h-4 bg-neutral-700 rounded"></div>
- <div className="h-4 bg-neutral-700 rounded w-32"></div>
+ <div className="h-3 bg-neutral-700 rounded w-20"></div>
</div>
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
+ ))}
+ </div>
+
+ {/* Add Site Section */}
+ <div className="border-t border-neutral-800 pt-2 mt-2">
+ <AddSite
+ trigger={
+ <Button variant="ghost" className="w-full justify-start gap-2">
+ <Plus className="h-4 w-4" />
+ Add New Site
+ </Button>
+ }
+ />
+ </div>
+ </PopoverContent>
);
}
@@ -71,21 +95,25 @@ export function SiteSelector() {
const { data: site } = useGetSite(currentSite);
return (
- <DropdownMenu>
- <DropdownMenuTrigger unstyled>
+ <Popover>
+ <PopoverTrigger asChild>
{site ? (
- <div className="flex gap-2 border border-neutral-800 rounded-lg py-1.5 px-3 justify-start cursor-pointer hover:bg-neutral-800/50 transition-colors h-[36px]">
+ <button className="flex gap-2 items-center border border-neutral-800 rounded-lg py-1.5 px-3 justify-start cursor-pointer hover:bg-neutral-800/50 transition-colors h-[36px] w-full">
<Favicon domain={site.domain} className="w-5 h-5" />
- <div className="text-white truncate text-sm">{site.domain}</div>
- </div>
+ <div className="text-white truncate text-sm flex-1 text-left">
+ {site.domain}
+ </div>
+ <ChevronDown className="w-4 h-4 text-neutral-400" />
+ </button>
) : (
- <div className="flex gap-2 border border-neutral-800 rounded-lg py-1.5 px-3 justify-start items-center h-[36px] animate-pulse">
+ <button className="flex gap-2 border border-neutral-800 rounded-lg py-1.5 px-3 justify-start items-center h-[36px] w-full animate-pulse">
<div className="w-5 h-5 bg-neutral-800 rounded"></div>
- <div className="h-4 bg-neutral-800 rounded w-24"></div>
- </div>
+ <div className="h-4 bg-neutral-800 rounded w-24 flex-1"></div>
+ <ChevronDown className="w-4 h-4 text-neutral-400" />
+ </button>
)}
- </DropdownMenuTrigger>
+ </PopoverTrigger>
{user && <SiteSelectorContent />}
- </DropdownMenu>
+ </Popover>
);
}
diff --git a/client/src/components/ui/popover.tsx b/client/src/components/ui/popover.tsx
index a21912a25..845729530 100644
--- a/client/src/components/ui/popover.tsx
+++ b/client/src/components/ui/popover.tsx
@@ -21,7 +21,7 @@ const PopoverContent = React.forwardRef<
align={align}
sideOffset={sideOffset}
className={cn(
- "z-50 w-72 rounded-md border border-neutral-200 bg-white p-4 text-neutral-950 shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-neutral-850 dark:bg-neutral-900 dark:text-neutral-50",
+ "z-50 w-72 rounded-md border border-neutral-200 bg-white p-4 text-neutral-950 shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-neutral-800 dark:bg-neutral-900 dark:text-neutral-50",
className
)}
{...props}
diff --git a/memory-bank/progress.md b/memory-bank/progress.md
index fa6866a72..cd6b6df9e 100644
--- a/memory-bank/progress.md
+++ b/memory-bank/progress.md
@@ -155,3 +155,23 @@ This file tracks the project's progress using a task list format.
- [`Overview.tsx`](client/src/app/[site]/main/components/MainSection/Overview.tsx:1) - Replaced 2 instances with `useGetOverview`
- **Final Status**: All TypeScript errors resolved, hook consolidation complete across entire codebase
- **Total Impact**: 9 analytics hook files now use centralized patterns, eliminating 100+ lines of duplicated code
+
+[2025-06-08 22:08:11] - **COMPLETED: SiteSelector UI Enhancement - Dropdown to Popover Conversion**
+
+- **Task**: Convert SiteSelector from dropdown menu to popover with enhanced functionality
+- **Status**: ✅ COMPLETED
+- **Work Done**:
+ - Replaced [`DropdownMenu`](client/src/components/ui/dropdown-menu.tsx:1) components with [`Popover`](client/src/components/ui/popover.tsx:1) components
+ - Enhanced site display to show sessions in past 24 hours using [`sessionsLast24Hours`](client/src/api/admin/sites.ts:60) field
+ - Integrated [`AddSite`](client/src/app/components/AddSite.tsx:1) component at bottom of popover for new site creation
+ - Added [`ChevronDown`](https://lucide.dev/icons/chevron-down) icon to trigger button
+ - Implemented scrollable container (`max-h-96 overflow-y-auto`) for better UX with many sites
+ - Enhanced skeleton loading states to match new layout structure
+- **Files Modified**:
+ - [`client/src/app/[site]/components/Sidebar/SiteSelector.tsx`](client/src/app/[site]/components/Sidebar/SiteSelector.tsx:1) - Complete UI transformation
+- **Features Added**:
+ - Site domain display with sessions count (e.g., "example.com - 42 sessions (24h)")
+ - Inline new site creation capability
+ - Improved visual hierarchy and spacing
+ - Better responsive design with scrolling support
+- **Impact**: Enhanced user experience for site management with richer information display and streamlined site creation workflow