Skip to content

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

Enhance Sidebar and TopBar components with session-based rendering

Bill Yangf0ad49af2388
diff --git a/client/src/app/[site]/components/Sidebar/Sidebar.tsx b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
index b1411524d..9c7ad0c02 100644
--- a/client/src/app/[site]/components/Sidebar/Sidebar.tsx
+++ b/client/src/app/[site]/components/Sidebar/Sidebar.tsx
@@ -15,8 +15,10 @@ import { useGetSite } from "../../../../api/admin/sites";
import { SiteSettings } from "../../../../components/SiteSettings/SiteSettings";
import LiveUserCount from "./LiveUserCount";
import { SiteSelector } from "./SiteSelector";
+import { authClient } from "../../../../lib/auth";
export function Sidebar() {
+ const session = authClient.useSession();
const pathname = usePathname();
const { data: site } = useGetSite(Number(pathname.split("/")[1]));
@@ -84,17 +86,19 @@ export function Sidebar() {
href={getTabPath("reports")}
icon={<ChartBarDecreasing className="w-4 h-4" />}
/>
- <SiteSettings
- siteId={site?.siteId ?? 0}
- trigger={
- <div className="px-3 py-2 rounded-lg transition-colors w-full text-neutral-200 hover:text-white hover:bg-neutral-800/50">
- <div className="flex items-center gap-2">
- <Settings className="h-4 w-4" />
- <span className="text-sm">Settings</span>
+ {session.data && (
+ <SiteSettings
+ siteId={site?.siteId ?? 0}
+ trigger={
+ <div className="px-3 py-2 rounded-lg transition-colors w-full text-neutral-200 hover:text-white hover:bg-neutral-800/50 cursor-pointer">
+ <div className="flex items-center gap-2">
+ <Settings className="h-4 w-4" />
+ <span className="text-sm">Settings</span>
+ </div>
</div>
- </div>
- }
- />
+ }
+ />
+ )}
</div>
</div>
);
diff --git a/client/src/components/Sessions/SessionDetails.tsx b/client/src/components/Sessions/SessionDetails.tsx
index 35c3d523c..2f83cdc8f 100644
--- a/client/src/components/Sessions/SessionDetails.tsx
+++ b/client/src/components/Sessions/SessionDetails.tsx
@@ -90,7 +90,7 @@ function PageviewItem({
<div className="flex-1 min-w-0 mr-4">
{item.type === "pageview" ? (
<Link
- href={`${item.hostname}${item.pathname}${
+ href={`https://${item.hostname}${item.pathname}${
item.querystring ? `${item.querystring}` : ""
}`}
target="_blank"
diff --git a/client/src/components/TopBar.tsx b/client/src/components/TopBar.tsx
index 4f1ecbd7c..774128a2e 100644
--- a/client/src/components/TopBar.tsx
+++ b/client/src/components/TopBar.tsx
@@ -11,6 +11,7 @@ import {
DropdownMenuTrigger,
} from "./ui/dropdown-menu";
import { User } from "lucide-react";
+import { Button } from "./ui/button";
export function TopBar() {
const session = authClient.useSession();
@@ -25,30 +26,38 @@ export function TopBar() {
🐸 Frogstats
</Link>
</div>
- <DropdownMenu>
- <DropdownMenuTrigger
- className="flex items-center gap-1 text-xs font-medium px-2 py-0"
- variant="ghost"
- >
- <User className="w-4 h-4" />
- {session.data?.user.name}
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <Link href="/settings/account" legacyBehavior passHref>
- <DropdownMenuItem>Settings</DropdownMenuItem>
- </Link>
- <DropdownMenuItem
- onClick={async () => {
- // Clear the query cache before signing out
- queryClient.clear();
- await authClient.signOut();
- router.push("/login");
- }}
+ {session.data ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ className="flex items-center gap-1 text-xs font-medium px-2 py-0"
+ variant="ghost"
>
- Sign out
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ <User className="w-4 h-4" />
+ {session.data?.user.name}
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <Link href="/settings/account" legacyBehavior passHref>
+ <DropdownMenuItem>Settings</DropdownMenuItem>
+ </Link>
+ <DropdownMenuItem
+ onClick={async () => {
+ // Clear the query cache before signing out
+ queryClient.clear();
+ await authClient.signOut();
+ router.push("/login");
+ }}
+ >
+ Sign out
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <Link href="/signup" legacyBehavior passHref>
+ <Button variant="ghost" size="sm">
+ Sign up
+ </Button>
+ </Link>
+ )}
</div>
</div>
);