Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(sidebar): start collapsed and open over the page on hover (#996)
Gökhan Geyik90c30ffb17b3
diff --git a/web/messages/en.json b/web/messages/en.jsonindex e3170044b..4edc0c2ff 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -62,6 +62,8 @@"analytics": "Analytics","optimization": "Optimization","toggleMenu": "Toggle navigation menu",+ "keepSidebarOpen": "Keep sidebar open",+ "collapseSidebar": "Collapse sidebar","feedback": "Send feedback"},"actionCenter": {diff --git a/web/src/app/[locale]/(dashboard)/layout.tsx b/web/src/app/[locale]/(dashboard)/layout.tsxindex 298363557..8c889f994 100644--- a/web/src/app/[locale]/(dashboard)/layout.tsx+++ b/web/src/app/[locale]/(dashboard)/layout.tsx@@ -87,7 +87,7 @@ export default async function DashboardLayout({ children }: { children: React.Re<RoleProvider role={role}><div className="flex h-screen overflow-hidden">{/* Desktop sidebar */}- <div className="hidden md:flex md:flex-shrink-0">+ <div className="relative hidden md:flex md:flex-shrink-0"><SidebarErrorBoundary><Sidebar /></SidebarErrorBoundary>diff --git a/web/src/components/layout/brand-switcher.tsx b/web/src/components/layout/brand-switcher.tsxindex 5e626bd3d..8f11bbdae 100644--- a/web/src/components/layout/brand-switcher.tsx+++ b/web/src/components/layout/brand-switcher.tsx@@ -18,9 +18,10 @@ import { Check, ChevronsUpDown, Plus } from 'lucide-react';interface BrandSwitcherProps {collapsed?: boolean;+ onOpenChange?: (open: boolean) => void;}-export function BrandSwitcher({ collapsed = false }: BrandSwitcherProps) {+export function BrandSwitcher({ collapsed = false, onOpenChange }: BrandSwitcherProps) {const t = useTranslations('brands');const router = useRouter();const { brands, activeBrandId, setActiveBrand } = useBrandStore();@@ -44,7 +45,7 @@ export function BrandSwitcher({ collapsed = false }: BrandSwitcherProps) {}return (- <DropdownMenu>+ <DropdownMenu onOpenChange={onOpenChange}><DropdownMenuTriggerclassName={cn('flex w-full items-center gap-2 rounded-md px-2 py-2 text-sm transition-colors hover:bg-sidebar-accent focus-visible:outline-none',diff --git a/web/src/components/layout/sidebar.tsx b/web/src/components/layout/sidebar.tsxindex 1c793333a..27f6da21f 100644--- a/web/src/components/layout/sidebar.tsx+++ b/web/src/components/layout/sidebar.tsx@@ -2,7 +2,7 @@import Image from 'next/image';import { useTheme } from 'next-themes';-import { useEffect, useState } from 'react';+import { useEffect, useRef, useState } from 'react';import { useTranslations } from 'next-intl';import { usePathname, Link } from '@/i18n/navigation';import { dashboardNav } from '@/config/dashboard';@@ -32,9 +32,19 @@ import {MessageSquareHeart,} from 'lucide-react';+/** How long the pointer rests on the collapsed sidebar before it opens. */+const PEEK_DELAY_MS = 150;+export function Sidebar() {const pathname = usePathname();const { isCollapsed, toggleCollapse } = useSidebarStore();+ // A collapsed sidebar opens over the page while the pointer is on it+ // ("peeking") and while its brand menu is open, and closes again after.+ const [peeking, setPeeking] = useState(false);+ const [menuOpen, setMenuOpen] = useState(false);+ const peekTimer = useRef<ReturnType<typeof setTimeout>>(undefined);+ const asideRef = useRef<HTMLElement>(null);+ const compact = isCollapsed && !peeking && !menuOpen;const t = useTranslations('nav');const tBrands = useTranslations('brands');const { canUse, requiredPlanFor, isCloud } = useFeatureGate();@@ -61,185 +71,240 @@ export function Sidebar() {setMounted(true);}, []);+ useEffect(() => () => clearTimeout(peekTimer.current), []);+const logoSrc = mounted && resolvedTheme === 'dark' ? '/logo_dark.svg' : '/logo_light.svg';+ function handleMouseEnter() {+ if (!isCollapsed) return;+ clearTimeout(peekTimer.current);+ peekTimer.current = setTimeout(() => setPeeking(true), PEEK_DELAY_MS);+ }++ function handleMouseLeave() {+ clearTimeout(peekTimer.current);+ setPeeking(false);+ }++ function handleMenuOpenChange(open: boolean) {+ setMenuOpen(open);+ if (open) return;+ // While the menu is open it covers the page, so the pointer can move off+ // the sidebar without a mouseleave. Check where it is on its next move.+ document.addEventListener(+ 'pointermove',+ (e) => {+ const rect = asideRef.current?.getBoundingClientRect();+ const inside =+ rect != null &&+ e.clientX >= rect.left &&+ e.clientX <= rect.right &&+ e.clientY >= rect.top &&+ e.clientY <= rect.bottom;+ if (!inside) setPeeking(false);+ },+ { once: true },+ );+ }++ function handleToggleCollapse() {+ // Collapsing takes effect at once, even with the pointer still on it.+ clearTimeout(peekTimer.current);+ setPeeking(false);+ toggleCollapse();+ }+return (- <aside- className={cn(- 'relative flex h-full flex-col border-r bg-sidebar transition-all duration-300',- isCollapsed ? 'w-16' : 'w-60',- )}- >+ <>+ {/* Holds the page layout at the pinned width. The sidebar itself is+ laid over it, so a collapsed one can widen over the page. */}<div- className={cn('flex h-16 items-center border-b px-3', isCollapsed && 'justify-center px-0')}+ aria-hidden+ className={cn('shrink-0 transition-[width] duration-200', isCollapsed ? 'w-16' : 'w-60')}+ />+ <aside+ ref={asideRef}+ onMouseEnter={handleMouseEnter}+ onMouseLeave={handleMouseLeave}+ className={cn(+ 'absolute inset-y-0 left-0 z-40 flex flex-col border-r bg-sidebar transition-[width] duration-200',+ compact ? 'w-16' : 'w-60',+ isCollapsed && !compact && 'shadow-xl',+ )}>- <Link- href="/dashboard"- className={cn('flex items-center gap-2 overflow-hidden', !isCollapsed && 'w-full')}+ <div+ className={cn('flex h-16 items-center border-b px-3', compact && 'justify-center px-0')}>- <Image- src={logoSrc}- alt={siteConfig.name}- width={24}- height={24}- className="h-6 w-6 shrink-0"- priority- />- {!isCollapsed && <span className="truncate font-semibold">{siteConfig.name}</span>}- </Link>- </div>-- <div className={cn('border-b px-2 py-2', isCollapsed && 'px-1')}>- <BrandSwitcher collapsed={isCollapsed} />- </div>-- <ScrollArea className="flex-1 px-2 py-3">- {dashboardNav.map((group, i) => (- <div key={i} className="mb-4">- {group.title && !isCollapsed && (- <p className="mb-1 px-2 text-xs font-medium uppercase tracking-wider text-muted-foreground">- {getDashboardNavGroupLabel(group.title, t)}- </p>- )}- {/* A group with no title has no header to set it apart, so it+ <Link+ href="/dashboard"+ className={cn('flex items-center gap-2 overflow-hidden', !compact && 'w-full')}+ >+ <Image+ src={logoSrc}+ alt={siteConfig.name}+ width={24}+ height={24}+ className="h-6 w-6 shrink-0"+ priority+ />+ {!compact && <span className="truncate font-semibold">{siteConfig.name}</span>}+ </Link>+ </div>++ <div className={cn('border-b px-2 py-2', compact && 'px-1')}>+ <BrandSwitcher collapsed={compact} onOpenChange={handleMenuOpenChange} />+ </div>++ <ScrollArea className="flex-1 px-2 py-3">+ {dashboardNav.map((group, i) => (+ <div key={i} className="mb-4">+ {group.title && !compact && (+ <p className="mb-1 px-2 text-xs font-medium uppercase tracking-wider text-muted-foreground">+ {getDashboardNavGroupLabel(group.title, t)}+ </p>+ )}+ {/* A group with no title has no header to set it apart, so itcarries a rule instead — without one its items read as the tailof the group above. The first group needs neither: nothingprecedes it. */}- {!group.title && i > 0 && <Separator className="mb-2" />}- {group.title && isCollapsed && i > 0 && <Separator className="my-2" />}- <nav className="space-y-0.5">- {group.items.map((item) => {- if (!shouldShowDashboardNavItem(item, brandPrefs)) {- return null;- }-- const isActive =- item.href === '/dashboard'- ? pathname === '/dashboard'- : pathname.startsWith(item.href);- const label = getDashboardNavLabel(item.title, t, tBrands);-- // Dynamic badge override: show "Set up" on the Agent item- // when the org has no Anthropic key saved (cloud only).- const effectiveBadge =- item.href === '/dashboard/agent' && agentKeyMissing ? 'Set up' : item.badge;-- const isLocked =- isCloud && item.requiredFeature != null && !canUse(item.requiredFeature);-- if (isLocked) {- return (- <span- key={item.href}- className={cn(- 'flex cursor-not-allowed items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium text-muted-foreground/50',- isCollapsed && 'justify-center',- )}- title={- isCollapsed- ? `${label} (${requiredPlanFor(item.requiredFeature!)})`- : undefined- }- >- <item.icon className="h-4 w-4 shrink-0" />- {!isCollapsed && (- <>- <span className="flex-1 truncate">{label}</span>- <Badge- variant="outline"- className="ml-auto h-5 shrink-0 gap-0.5 px-1.5 text-[10px] font-normal"- >- <Crown className="h-2.5 w-2.5" />- {requiredPlanFor(item.requiredFeature!)}- </Badge>- </>- )}- {isCollapsed && (- <Lock className="absolute right-1 top-1 h-2.5 w-2.5 text-muted-foreground/40" />- )}- </span>- );- }-- return (- <Link key={item.href} href={item.href}>- <span- className={cn(- 'flex items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium transition-colors',- isActive- ? 'bg-primary/10 text-primary'- : 'text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',- isCollapsed && 'justify-center',- )}- title={- isCollapsed- ? effectiveBadge- ? `${label} (${effectiveBadge})`- : label- : undefined- }- >- <item.icon className="h-4 w-4 shrink-0" />- {!isCollapsed && (- <>- <span className="flex-1 truncate">{label}</span>- {effectiveBadge && (+ {!group.title && i > 0 && <Separator className="mb-2" />}+ {group.title && compact && i > 0 && <Separator className="my-2" />}+ <nav className="space-y-0.5">+ {group.items.map((item) => {+ if (!shouldShowDashboardNavItem(item, brandPrefs)) {+ return null;+ }++ const isActive =+ item.href === '/dashboard'+ ? pathname === '/dashboard'+ : pathname.startsWith(item.href);+ const label = getDashboardNavLabel(item.title, t, tBrands);++ // Dynamic badge override: show "Set up" on the Agent item+ // when the org has no Anthropic key saved (cloud only).+ const effectiveBadge =+ item.href === '/dashboard/agent' && agentKeyMissing ? 'Set up' : item.badge;++ const isLocked =+ isCloud && item.requiredFeature != null && !canUse(item.requiredFeature);++ if (isLocked) {+ return (+ <span+ key={item.href}+ className={cn(+ 'flex cursor-not-allowed items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium text-muted-foreground/50',+ compact && 'justify-center',+ )}+ title={+ compact+ ? `${label} (${requiredPlanFor(item.requiredFeature!)})`+ : undefined+ }+ >+ <item.icon className="h-4 w-4 shrink-0" />+ {!compact && (+ <>+ <span className="flex-1 truncate">{label}</span><Badge- variant="secondary"- className="ml-auto h-5 shrink-0 px-1.5 text-[10px] font-normal"+ variant="outline"+ className="ml-auto h-5 shrink-0 gap-0.5 px-1.5 text-[10px] font-normal">- {effectiveBadge}+ <Crown className="h-2.5 w-2.5" />+ {requiredPlanFor(item.requiredFeature!)}</Badge>- )}- </>- )}- </span>- </Link>- );- })}- </nav>- </div>- ))}- </ScrollArea>-- <div className="space-y-1 p-2">- <a- href={siteConfig.links.feedback}- target="_blank"- rel="noopener noreferrer"- title={isCollapsed ? t('feedback') : undefined}- className={cn(- 'flex items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium text-muted-foreground transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',- isCollapsed && 'justify-center',- )}- >- <MessageSquareHeart className="h-4 w-4 shrink-0" />- {!isCollapsed && (- <>- <span className="flex-1 truncate">{t('feedback')}</span>- <ExternalLink className="h-3 w-3 shrink-0 opacity-60" />- </>- )}- </a>- <Button- variant="ghost"- onClick={toggleCollapse}- className={cn(- 'flex h-9 w-full items-center gap-2 px-2',- isCollapsed ? 'justify-center' : 'justify-start',- )}- >- {isCollapsed ? (- <ChevronsRight className="h-4 w-4" />- ) : (- <ChevronsLeft className="h-4 w-4" />- )}- </Button>- </div>-- <div className="border-t p-2">- <UserProfileNavItem collapsed={isCollapsed} />- </div>- </aside>+ </>+ )}+ {compact && (+ <Lock className="absolute right-1 top-1 h-2.5 w-2.5 text-muted-foreground/40" />+ )}+ </span>+ );+ }++ return (+ <Link key={item.href} href={item.href}>+ <span+ className={cn(+ 'flex items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium transition-colors',+ isActive+ ? 'bg-primary/10 text-primary'+ : 'text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',+ compact && 'justify-center',+ )}+ title={+ compact+ ? effectiveBadge+ ? `${label} (${effectiveBadge})`+ : label+ : undefined+ }+ >+ <item.icon className="h-4 w-4 shrink-0" />+ {!compact && (+ <>+ <span className="flex-1 truncate">{label}</span>+ {effectiveBadge && (+ <Badge+ variant="secondary"+ className="ml-auto h-5 shrink-0 px-1.5 text-[10px] font-normal"+ >+ {effectiveBadge}+ </Badge>+ )}+ </>+ )}+ </span>+ </Link>+ );+ })}+ </nav>+ </div>+ ))}+ </ScrollArea>++ <div className="space-y-1 p-2">+ <a+ href={siteConfig.links.feedback}+ target="_blank"+ rel="noopener noreferrer"+ title={compact ? t('feedback') : undefined}+ className={cn(+ 'flex items-center gap-3 rounded-md px-2 py-1.5 text-[13px] font-medium text-muted-foreground transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',+ compact && 'justify-center',+ )}+ >+ <MessageSquareHeart className="h-4 w-4 shrink-0" />+ {!compact && (+ <>+ <span className="flex-1 truncate">{t('feedback')}</span>+ <ExternalLink className="h-3 w-3 shrink-0 opacity-60" />+ </>+ )}+ </a>+ <Button+ variant="ghost"+ onClick={handleToggleCollapse}+ aria-label={isCollapsed ? t('keepSidebarOpen') : t('collapseSidebar')}+ title={isCollapsed ? t('keepSidebarOpen') : t('collapseSidebar')}+ className={cn(+ 'flex h-9 w-full items-center gap-2 px-2',+ compact ? 'justify-center' : 'justify-start',+ )}+ >+ {isCollapsed ? (+ <ChevronsRight className="h-4 w-4" />+ ) : (+ <ChevronsLeft className="h-4 w-4" />+ )}+ </Button>+ </div>++ <div className="border-t p-2">+ <UserProfileNavItem collapsed={compact} />+ </div>+ </aside>+ </>);}diff --git a/web/src/stores/use-sidebar-store.ts b/web/src/stores/use-sidebar-store.tsindex 5bc4dac49..268cd228d 100644--- a/web/src/stores/use-sidebar-store.ts+++ b/web/src/stores/use-sidebar-store.ts@@ -14,7 +14,9 @@ export const useSidebarStore = create<SidebarStore>()(persist((set) => ({isOpen: true,- isCollapsed: false,+ // Collapsed by default: the sidebar opens over the page on hover, and+ // its button keeps it open for those who want it pinned.+ isCollapsed: true,toggle: () => set((state) => ({ isOpen: !state.isOpen })),open: () => set({ isOpen: true }),close: () => set({ isOpen: false }),@@ -22,6 +24,11 @@ export const useSidebarStore = create<SidebarStore>()(}),{name: 'sidebar-store',+ // Version 1 made collapsed the default. A stored state from before it+ // holds the old default rather than a choice, so it starts collapsed too.+ version: 1,+ migrate: (persisted, version) =>+ version < 1 ? { ...(persisted as SidebarStore), isCollapsed: true } : persisted,},),);