Skip to content

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

Update SiteSelector and SessionCard components for improved functionality and layout

Bill Yang19167a552374
diff --git a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
index cad6261dd..5efd867c0 100644
--- a/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
+++ b/client/src/app/[site]/components/Sidebar/SiteSelector.tsx
@@ -31,10 +31,10 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {
<PopoverContent align="start" className="w-52 p-2">
<div className="max-h-96 overflow-y-auto">
{[
- // {
- // siteId: 21,
- // domain: "rybbit.com",
- // },
+ {
+ siteId: 81,
+ domain: "rybbit.com",
+ },
{
siteId: 1,
domain: "tomato.gg",
@@ -83,52 +83,52 @@ function SiteSelectorContent({ onSiteSelect }: { onSiteSelect: () => void }) {
<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) {
- onSiteSelect(); // Close popover even if same site
- return;
- }
- const pathSegments = pathname.split("/");
- pathSegments[1] = site.siteId.toString();
- const newPath = pathSegments.join("/");
- const queryString = window.location.search;
- // Let the layout's useEffect sync the site from the new pathname
- router.push(queryString ? `${newPath}${queryString}` : newPath);
- onSiteSelect(); // Close popover immediately
- }}
- className={cn(
- "flex items-center justify-between p-2 cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-800/50 transition-colors rounded-md border-b border-neutral-100 dark:border-neutral-800 last:border-b-0",
- isSelected && "bg-neutral-50 dark:bg-neutral-800"
- )}
- >
- <div className="flex items-center gap-3 flex-1 min-w-0">
- <Favicon domain={site.domain} className="w-4 h-4 shrink-0" />
- <div className="text-sm text-neutral-900 dark:text-white truncate">{site.domain}</div>
- </div>
- <div className="flex items-center gap-3">
- <div className="text-xs text-neutral-600 dark:text-neutral-300 whitespace-nowrap">
- {formatter(site.sessionsLast24Hours)} sessions (24h)
- </div>
- </div>
- </div>
- );
- })
- : Array.from({ length: 3 }).map((_, index) => (
+ const isSelected = site.siteId === currentSiteId;
+ return (
<div
- key={`skeleton-${index}`}
- className="flex items-center justify-between p-2 animate-pulse rounded-md border-b border-neutral-300 dark:border-neutral-800 last:border-b-0"
+ key={site.siteId}
+ onClick={() => {
+ if (isSelected) {
+ onSiteSelect(); // Close popover even if same site
+ return;
+ }
+ const pathSegments = pathname.split("/");
+ pathSegments[1] = site.siteId.toString();
+ const newPath = pathSegments.join("/");
+ const queryString = window.location.search;
+ // Let the layout's useEffect sync the site from the new pathname
+ router.push(queryString ? `${newPath}${queryString}` : newPath);
+ onSiteSelect(); // Close popover immediately
+ }}
+ className={cn(
+ "flex items-center justify-between p-2 cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-800/50 transition-colors rounded-md border-b border-neutral-100 dark:border-neutral-800 last:border-b-0",
+ isSelected && "bg-neutral-50 dark:bg-neutral-800"
+ )}
>
- <div className="flex items-center gap-3 flex-1">
- <div className="w-4 h-4 bg-neutral-200 dark:bg-neutral-700 rounded shrink-0"></div>
- <div className="h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-32"></div>
+ <div className="flex items-center gap-3 flex-1 min-w-0">
+ <Favicon domain={site.domain} className="w-4 h-4 shrink-0" />
+ <div className="text-sm text-neutral-900 dark:text-white truncate">{site.domain}</div>
+ </div>
+ <div className="flex items-center gap-3">
+ <div className="text-xs text-neutral-600 dark:text-neutral-300 whitespace-nowrap">
+ {formatter(site.sessionsLast24Hours)} sessions (24h)
+ </div>
</div>
- <div className="h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-20"></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-300 dark:border-neutral-800 last:border-b-0"
+ >
+ <div className="flex items-center gap-3 flex-1">
+ <div className="w-4 h-4 bg-neutral-200 dark:bg-neutral-700 rounded shrink-0"></div>
+ <div className="h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-32"></div>
+ </div>
+ <div className="h-3 bg-neutral-200 dark:bg-neutral-700 rounded w-20"></div>
+ </div>
+ ))}
</div>
{/* Add Site Section */}
diff --git a/client/src/app/[site]/user/[userId]/page.tsx b/client/src/app/[site]/user/[userId]/page.tsx
index eb5279514..f31796e78 100644
--- a/client/src/app/[site]/user/[userId]/page.tsx
+++ b/client/src/app/[site]/user/[userId]/page.tsx
@@ -103,12 +103,14 @@ export default function UserPage() {
</>
)}
</div>
- {data?.ip && (
- <Badge variant="outline" className="mt-3 text-xs">
+ </div>
+ {data?.ip && (
+ <div>
+ <Badge variant="outline" className="text-xs whitespace-nowrap">
IP: {data.ip}
</Badge>
- )}
- </div>
+ </div>
+ )}
</div>
{/* Main two-column layout */}
diff --git a/client/src/components/Sessions/SessionCard.tsx b/client/src/components/Sessions/SessionCard.tsx
index fead32414..e8ddf42c0 100644
--- a/client/src/components/Sessions/SessionCard.tsx
+++ b/client/src/components/Sessions/SessionCard.tsx
@@ -1,9 +1,11 @@
import { Skeleton } from "@/components/ui/skeleton";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { addFilter, getTimezone } from "@/lib/store";
+import { FilterParameter } from "@rybbit/shared";
import { ArrowRight, ChevronDown, ChevronRight, Video } from "lucide-react";
import { DateTime } from "luxon";
-import { FilterParameter } from "@rybbit/shared";
+import Link from "next/link";
+import { useParams } from "next/navigation";
import { memo, useCallback, useState } from "react";
import { GetSessionsResponse } from "../../api/analytics/endpoints";
import { formatShortDuration, hour12, userLocale } from "../../lib/dateTimeUtils";
@@ -19,8 +21,8 @@ import {
OperatingSystemTooltipIcon,
} from "../TooltipIcons/TooltipIcons";
import { Badge } from "../ui/badge";
-import { SessionDetails } from "./SessionDetails";
import { ReplayDrawer } from "./ReplayDrawer";
+import { SessionDetails } from "./SessionDetails";
interface SessionCardProps {
session: GetSessionsResponse[number];
@@ -30,6 +32,7 @@ interface SessionCardProps {
}
export function SessionCard({ session, onClick, userId, expandedByDefault }: SessionCardProps) {
+ const { site } = useParams();
const [expanded, setExpanded] = useState(expandedByDefault || false);
const [replayDrawerOpen, setReplayDrawerOpen] = useState(false);
// Calculate session duration in minutes
@@ -37,6 +40,7 @@ export function SessionCard({ session, onClick, userId, expandedByDefault }: Ses
const end = DateTime.fromSQL(session.session_end);
const totalSeconds = Math.floor(end.diff(start).milliseconds / 1000);
const duration = formatShortDuration(totalSeconds);
+ const isIdentified = !!session.identified_user_id;
const handleCardClick = () => {
if (onClick) {
@@ -158,17 +162,23 @@ export function SessionCard({ session, onClick, userId, expandedByDefault }: Ses
{/* Desktop layout - single row */}
<div className="hidden md:flex items-center gap-2">
{!userId && (
- <div className="flex items-center gap-2">
+ <Link
+ href={`/${site}/user/${encodeURIComponent(
+ isIdentified ? session.identified_user_id : session.user_id
+ )}`}
+ onClick={e => e.stopPropagation()}
+ className="flex items-center gap-2"
+ >
<Avatar
size={24}
id={session.user_id}
lastActiveTime={DateTime.fromSQL(session.session_end, { zone: "utc" })}
/>
- <span className="text-xs text-neutral-600 dark:text-neutral-200 w-24 truncate">
+ <span className="text-xs text-neutral-600 dark:text-neutral-200 w-24 truncate hover:underline">
{getUserDisplayName(session)}
</span>
{!!session.identified_user_id && <IdentifiedBadge traits={session.traits} />}
- </div>
+ </Link>
)}
{/* Icons section */}