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): switch between light and dark mode beside the logo (#1200)
Cihan4f9da9ee8ab7
diff --git a/web/messages/en.json b/web/messages/en.jsonindex a83b34441..8a89652a7 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -64,6 +64,8 @@"toggleMenu": "Toggle navigation menu","keepSidebarOpen": "Keep sidebar open","collapseSidebar": "Collapse sidebar",+ "switchToDark": "Switch to dark mode",+ "switchToLight": "Switch to light mode","feedback": "Send feedback","trackedPrompts": "Tracked Prompts","promptSuggestions": "Prompt Suggestions",@@ -4214,8 +4216,6 @@"description": "Manage your project and account settings.","account": "Account","accountDescription": "Your profile and sign-in details.",- "theme": "Theme",- "themeDescription": "Choose light or dark mode for the dashboard.","general": "General","apiKeys": "API Keys","team": "Team",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsxindex 6a5c70415..8253d00b8 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx@@ -10,7 +10,6 @@ import { Input } from '@/components/ui/input';import { Label } from '@/components/ui/label';import { Button } from '@/components/ui/button';import { Separator } from '@/components/ui/separator';-import { ThemeSwitch } from '@/components/settings/theme-switch';import { cn } from '@/lib/utils';import { usePlanContext } from '@/components/providers/plan-provider';import { BillingSection } from '@/components/settings/billing-section';@@ -26,7 +25,6 @@ import { toast } from 'sonner';type Section =| 'account'- | 'theme'| 'organization'| 'team'| 'notifications'@@ -86,7 +84,6 @@ export default function SettingsPage() {const navItems: { id: Section; label: string }[] = [{ id: 'account', label: t('account') },- { id: 'theme', label: t('theme') },{ id: 'organization', label: t('organization') },{ id: 'team', label: t('team') },{ id: 'notifications', label: t('notifications') },@@ -172,21 +169,6 @@ export default function SettingsPage() {</Card>)}- {/* Theme */}- {active === 'theme' && (- <div className="space-y-6">- <Card>- <CardHeader>- <CardTitle>{t('theme')}</CardTitle>- <CardDescription>{t('themeDescription')}</CardDescription>- </CardHeader>- <CardContent>- <ThemeSwitch />- </CardContent>- </Card>- </div>- )}-{/* Organization */}{active === 'organization' && <OrganizationSection />}diff --git a/web/src/components/layout/mobile-nav.tsx b/web/src/components/layout/mobile-nav.tsxindex 7b9d9c678..01a70d769 100644--- a/web/src/components/layout/mobile-nav.tsx+++ b/web/src/components/layout/mobile-nav.tsx@@ -13,6 +13,7 @@ import { Button } from '@/components/ui/button';import { Badge } from '@/components/ui/badge';import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet';import { UserProfileNavItem } from '@/components/layout/user-profile-nav-item';+import { ThemeToggle } from '@/components/layout/theme-toggle';import { useBrandStore } from '@/stores/use-brand-store';import { Crown, ExternalLink, Menu, MessageSquareHeart, MessageSquareText } from 'lucide-react';import Image from 'next/image';@@ -64,6 +65,8 @@ export function MobileNav() {priority/><span className="font-semibold">{siteConfig.name}</span>+ {/* Left of the sheet's close button, which sits at its top right. */}+ <ThemeToggle className="ml-auto mr-8" /></div><div className="min-h-0 flex-1 overflow-y-auto"><nav className="space-y-0.5 p-3">diff --git a/web/src/components/layout/sidebar.tsx b/web/src/components/layout/sidebar.tsxindex 53f11c455..99777fbb3 100644--- a/web/src/components/layout/sidebar.tsx+++ b/web/src/components/layout/sidebar.tsx@@ -26,6 +26,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';import { Separator } from '@/components/ui/separator';import { BrandSwitcher } from '@/components/layout/brand-switcher';import { UserProfileNavItem } from '@/components/layout/user-profile-nav-item';+import { ThemeToggle } from '@/components/layout/theme-toggle';import {ChevronDown,ChevronsLeft,@@ -269,11 +270,14 @@ export function Sidebar() {)}><div- className={cn('flex h-16 items-center border-b px-3', compact && 'justify-center px-0')}+ className={cn(+ 'flex h-16 items-center gap-2 border-b px-3',+ compact && 'justify-center px-0',+ )}><Linkhref="/dashboard"- className={cn('flex items-center gap-2 overflow-hidden', !compact && 'w-full')}+ className={cn('flex items-center gap-2 overflow-hidden', !compact && 'min-w-0 flex-1')}><Imagesrc={logoSrc}@@ -285,6 +289,9 @@ export function Sidebar() {/>{!compact && <span className="truncate font-semibold">{siteConfig.name}</span>}</Link>+ {/* Too narrow beside the logo when collapsed; it shows while the+ sidebar is open over the page. */}+ {!compact && <ThemeToggle className="shrink-0" />}</div><div className={cn('border-b px-2 py-2', compact && 'px-1')}>@@ -511,7 +518,8 @@ export function Sidebar() {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',+ // In the menu items' gray, not the button's black.+ 'flex h-9 w-full items-center gap-2 px-2 text-muted-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',compact ? 'justify-center' : 'justify-start',)}>diff --git a/web/src/components/layout/theme-toggle.test.tsx b/web/src/components/layout/theme-toggle.test.tsxnew file mode 100644index 000000000..eff5b4bd6--- /dev/null+++ b/web/src/components/layout/theme-toggle.test.tsx@@ -0,0 +1,62 @@+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { NextIntlClientProvider } from 'next-intl';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import messages from '../../../messages/en.json';+import { ThemeToggle } from './theme-toggle';++(+ globalThis as typeof globalThis & {+ IS_REACT_ACT_ENVIRONMENT: boolean;+ }+).IS_REACT_ACT_ENVIRONMENT = true;++const theme = vi.hoisted(() => ({ resolved: 'light', set: vi.fn() }));++vi.mock('next-themes', () => ({+ useTheme: () => ({ resolvedTheme: theme.resolved, setTheme: theme.set }),+}));++let container: HTMLDivElement;+let root: Root;++function render() {+ act(() => {+ root.render(+ <NextIntlClientProvider locale="en" messages={messages}>+ <ThemeToggle />+ </NextIntlClientProvider>,+ );+ });+ return container.querySelector('button')!;+}++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+ theme.set.mockClear();+});++afterEach(() => {+ act(() => root.unmount());+ container.remove();+});++describe('ThemeToggle', () => {+ it('offers dark mode while the dashboard is light, and switches to it', () => {+ theme.resolved = 'light';+ const button = render();+ expect(button.getAttribute('aria-label')).toBe('Switch to dark mode');+ act(() => button.click());+ expect(theme.set).toHaveBeenCalledWith('dark');+ });++ it('offers light mode while the dashboard is dark, and switches back', () => {+ theme.resolved = 'dark';+ const button = render();+ expect(button.getAttribute('aria-label')).toBe('Switch to light mode');+ act(() => button.click());+ expect(theme.set).toHaveBeenCalledWith('light');+ });+});diff --git a/web/src/components/layout/theme-toggle.tsx b/web/src/components/layout/theme-toggle.tsxnew file mode 100644index 000000000..636976821--- /dev/null+++ b/web/src/components/layout/theme-toggle.tsx@@ -0,0 +1,41 @@+'use client';++import { useCallback, useSyncExternalStore } from 'react';+import { useTranslations } from 'next-intl';+import { useTheme } from 'next-themes';+import { Moon, Sun } from 'lucide-react';+import { Button } from '@/components/ui/button';++const emptySubscribe = () => () => {};++/**+ * Switches the dashboard between light and dark, beside the logo in the+ * sidebar and the mobile menu. Light is the default (the ThemeProvider in+ * [locale]/layout.tsx); next-themes remembers the choice per browser. The+ * theme isn't known before mount, so it shows the light state until then,+ * as the logo does.+ */+export function ThemeToggle({ className }: { className?: string }) {+ const t = useTranslations('nav');+ const { resolvedTheme, setTheme } = useTheme();+ const mounted = useSyncExternalStore(+ emptySubscribe,+ useCallback(() => true, []),+ useCallback(() => false, []),+ );+ const dark = mounted && resolvedTheme === 'dark';+ const label = dark ? t('switchToLight') : t('switchToDark');++ return (+ <Button+ variant="ghost"+ size="icon-sm"+ className={className}+ onClick={() => setTheme(dark ? 'light' : 'dark')}+ aria-label={label}+ title={label}+ >+ {dark ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}+ </Button>+ );+}diff --git a/web/src/components/settings/theme-switch.tsx b/web/src/components/settings/theme-switch.tsxdeleted file mode 100644index c580c0ef8..000000000--- a/web/src/components/settings/theme-switch.tsx+++ /dev/null@@ -1,60 +0,0 @@-'use client';--import { useSyncExternalStore, useCallback } from 'react';-import { useTheme } from 'next-themes';-import { Button } from '@/components/ui/button';-import { Moon, Sun } from 'lucide-react';-import { cn } from '@/lib/utils';--const emptySubscribe = () => () => {};--export function ThemeSwitch() {- const { theme, setTheme } = useTheme();- const mounted = useSyncExternalStore(- emptySubscribe,- useCallback(() => true, []),- useCallback(() => false, []),- );-- if (!mounted) {- return (- <div className="flex rounded-lg border bg-muted p-1">- <div className="flex-1 rounded-md bg-muted/50 py-2 text-center text-sm text-muted-foreground">- Light- </div>- <div className="flex-1 rounded-md py-2 text-center text-sm text-muted-foreground">Dark</div>- </div>- );- }-- return (- <div className="flex rounded-lg border bg-muted p-1">- <Button- variant="ghost"- size="sm"- className={cn(- 'flex-1 gap-2 transition-colors',- theme === 'light' &&- 'bg-background text-foreground shadow-sm dark:border-input dark:bg-input/30',- )}- onClick={() => setTheme('light')}- >- <Sun className="h-4 w-4" />- Light- </Button>- <Button- variant="ghost"- size="sm"- className={cn(- 'flex-1 gap-2 transition-colors',- theme === 'dark' &&- 'bg-background text-foreground shadow-sm dark:border-input dark:bg-input/30',- )}- onClick={() => setTheme('dark')}- >- <Moon className="h-4 w-4" />- Dark- </Button>- </div>- );-}