🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance SiteSelector component with dynamic site selection and user h… (#436)
Bill Yang7d12740912c1
diff --git a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx b/client/src/app/[site]/components/Sidebar/SiteSelector.tsxindex 4daa09812..19b58253e 100644--- a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx+++ b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx@@ -24,6 +24,65 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {const router = useRouter();const currentSiteId = Number(pathname.split("/")[1]);+ const { user } = userStore();++ if (+ typeof window !== "undefined" &&+ globalThis.location.hostname === "demo.rybbit.io"+ ) {+ return (+ <PopoverContent align="start" className="w-52 p-2">+ <div className="max-h-96 overflow-y-auto">+ {[+ {+ siteId: 21,+ domain: "rybbit.io",+ },+ {+ siteId: 1,+ domain: "tomato.gg",+ },+ ].map((site) => {+ const isSelected = site.siteId === currentSiteId;+ return (+ <div+ key={site.siteId}+ onClick={() => {+ if (isSelected) {+ onSiteSelect(); // Close popover even if same site+ return;+ }+ resetStore();+ setSite(site.siteId.toString());+ router.push(`/${site.siteId}`);+ onSiteSelect(); // Close popover immediately+ }}+ 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>+ );+ })}+ </div>+ </PopoverContent>+ );+ }++ if (!user) {+ return null;+ }+return (<PopoverContent align="start" className="w-80 p-2"><div className="max-h-96 overflow-y-auto">@@ -95,7 +154,6 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {}export function SiteSelector() {- const { user } = userStore();const { site: currentSite } = useStore();const { data: site } = useGetSite(currentSite);const [open, setOpen] = useState(false);@@ -119,7 +177,7 @@ export function SiteSelector() {</button>)}</PopoverTrigger>- {user && <SiteSelectorContent onSiteSelect={() => setOpen(false)} />}+ <SiteSelectorContent onSiteSelect={() => setOpen(false)} /></Popover>);}diff --git a/docs/src/app/page.jsx b/docs/src/app/page.jsxindex 6228eafcd..97bfdeaf0 100644--- a/docs/src/app/page.jsx+++ b/docs/src/app/page.jsx@@ -122,7 +122,7 @@ export default function IndexPage() {</button></Link><Link- href="https://demo.rybbit.io/1"+ href="https://demo.rybbit.io/21"className="w-full sm:w-auto"data-rybbit-event="demo">@@ -153,7 +153,7 @@ export default function IndexPage() {<div className="relative z-10 rounded-lg overflow-hidden border-4 border-neutral-100/5 shadow-2xl shadow-emerald-900/10">{/* Remove mobile message and show iframe on all devices */}<iframe- src="https://demo.rybbit.io/1"+ src="https://demo.rybbit.io/21"width="1300"height="750"className="w-full h-[600px] md:h-[700px] lg:h-[750px]"@@ -316,7 +316,7 @@ export default function IndexPage() {<p>You can see for yourself by checking out our{" "}<Link- href="https://demo.rybbit.io/1"+ href="https://demo.rybbit.io/21"className="text-emerald-400 hover:text-emerald-300">demo site