diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 848d8385..c78e2a63 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -5,6 +5,7 @@ import { SessionMonitor } from "./components/SessionMonitor"; import Index from "./pages/Index"; import Clone from "./pages/Clone"; import Settings from "./pages/Settings"; +import Preferences from "./pages/Preferences"; import NostrSettings from "./pages/NostrSettings"; import AISettings from "./pages/AISettings"; import GitSettings from "./pages/GitSettings"; @@ -26,6 +27,7 @@ export function AppRouter() { } /> }> } /> + } /> } /> } /> } /> diff --git a/src/components/AIMessageItem.tsx b/src/components/AIMessageItem.tsx index 9c693988..0f8a9354 100644 --- a/src/components/AIMessageItem.tsx +++ b/src/components/AIMessageItem.tsx @@ -5,6 +5,7 @@ import type { AIMessage } from '@/lib/SessionManager'; import { cn } from '@/lib/utils'; import { UserMessage } from '@/components/UserMessage'; import OpenAI from 'openai'; +import { useTheme } from '@/hooks/useTheme'; interface AIMessageItemProps { message: AIMessage; @@ -18,6 +19,7 @@ export const AIMessageItem = memo(({ toolCall }: AIMessageItemProps) => { const [isToolExpanded, setIsToolExpanded] = useState(false); + const { displayTheme } = useTheme(); // Get content to display const getContent = () => { @@ -232,6 +234,7 @@ export const AIMessageItem = memo(({ {getContent()} diff --git a/src/components/ProjectSidebar.test.tsx b/src/components/ProjectSidebar.test.tsx index f3aaf27c..a94ca9e6 100644 --- a/src/components/ProjectSidebar.test.tsx +++ b/src/components/ProjectSidebar.test.tsx @@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { ProjectSidebar } from './ProjectSidebar'; import { useProjects } from '@/hooks/useProjects'; import { useLocalStorage } from '@/hooks/useLocalStorage'; +import { TestApp } from '@/test/TestApp'; // Mock the hooks vi.mock('@/hooks/useProjects'); @@ -10,14 +11,23 @@ vi.mock('@/hooks/useLocalStorage'); vi.mock('@/hooks/useProjectSessionStatus', () => ({ useProjectSessionStatus: () => ({ hasRunningSessions: false }) })); -vi.mock('react-router-dom', () => ({ - useNavigate: () => vi.fn() -})); -vi.mock('@tanstack/react-query', () => ({ - useQueryClient: () => ({ - invalidateQueries: vi.fn() - }) -})); +vi.mock('react-router-dom', async (importOriginal) => { + const actual = await importOriginal() as Record; + return { + ...actual, + useNavigate: () => vi.fn() + }; +}); +vi.mock('@tanstack/react-query', async (importOriginal) => { + const actual = await importOriginal() as Record; + return { + ...actual, + useQueryClient: () => ({ + invalidateQueries: vi.fn(), + resetQueries: vi.fn() + }) + }; +}); // Mock window.open for help button test const mockWindowOpen = vi.fn(); @@ -42,10 +52,12 @@ describe('ProjectSidebar', () => { it('renders sidebar header with logo', () => { render( - + + + ); expect(screen.getByText('🎭')).toBeInTheDocument(); @@ -56,11 +68,13 @@ describe('ProjectSidebar', () => { const mockToggle = vi.fn(); render( - + + + ); const collapseButton = screen.getByLabelText('Collapse sidebar'); @@ -72,10 +86,12 @@ describe('ProjectSidebar', () => { it('does not show collapse button when onToggleSidebar is not provided', () => { render( - + + + ); expect(screen.queryByLabelText('Collapse sidebar')).not.toBeInTheDocument(); @@ -83,10 +99,12 @@ describe('ProjectSidebar', () => { it('renders settings and help buttons at the bottom', () => { render( - + + + ); expect(screen.getByText('Settings')).toBeInTheDocument(); @@ -95,10 +113,12 @@ describe('ProjectSidebar', () => { it('shows new project button', () => { render( - + + + ); expect(screen.getByText('New Project')).toBeInTheDocument(); @@ -106,10 +126,12 @@ describe('ProjectSidebar', () => { it('opens help documentation when help button is clicked', () => { render( - + + + ); const helpButton = screen.getByLabelText('Help'); diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index 2136eb08..48653446 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -90,8 +90,8 @@ export function ProjectSidebar({ const queryClient = useQueryClient(); const { data: projects = [], isLoading, error } = useProjects(); const [favorites] = useLocalStorage('project-favorites', []); - const isMobile = useIsMobile(); + const isMobile = useIsMobile(); const navigate = useNavigate(); // Custom navigate function that closes sidebar on mobile @@ -229,20 +229,20 @@ export function ProjectSidebar({ diff --git a/src/components/SettingsLayout.tsx b/src/components/SettingsLayout.tsx index 9e1edf0a..48d6de46 100644 --- a/src/components/SettingsLayout.tsx +++ b/src/components/SettingsLayout.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import { useNavigate, useLocation, Outlet } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Menu, Bot, GitBranch, Database, Wifi } from 'lucide-react'; +import { Menu, Bot, GitBranch, Database, Wifi, Settings2 } from 'lucide-react'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useIsMobile } from '@/hooks/useIsMobile'; @@ -19,6 +19,13 @@ interface SettingsItem { } const settingsItems: SettingsItem[] = [ + { + id: 'preferences', + title: 'Preferences', + description: 'General application preferences and appearance', + icon: Settings2, + href: '/settings/preferences', + }, { id: 'ai', title: 'AI Settings', @@ -102,9 +109,9 @@ export function SettingsLayout() { if (isMobile) { return ( -
+
{/* Mobile Header */} -
+
+ + + {themeOptions.map((option) => { + const Icon = option.icon; + return ( + setTheme(option.value)} + className="flex items-center gap-2" + > + + {option.label} + {theme === option.value && ( +
+ )} + + ); + })} + + + ); +} \ No newline at end of file diff --git a/src/hooks/useSystemTheme.ts b/src/hooks/useSystemTheme.ts new file mode 100644 index 00000000..d561c776 --- /dev/null +++ b/src/hooks/useSystemTheme.ts @@ -0,0 +1,24 @@ +import { useEffect, useState } from "react"; + +export function useSystemTheme() { + const getSystemTheme = (): "dark" | "light" => + window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; + + const [theme, setTheme] = useState<"dark" | "light">(getSystemTheme); + + useEffect(() => { + const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); + + const handler = (event: MediaQueryListEvent): void => { + setTheme(event.matches ? "dark" : "light"); + }; + + // Attach listener + mediaQuery.addEventListener("change", handler); + + // Cleanup + return () => mediaQuery.removeEventListener("change", handler); + }, []); + + return theme; +} diff --git a/src/hooks/useTheme.ts b/src/hooks/useTheme.ts index 24f7a5d6..8ad41716 100644 --- a/src/hooks/useTheme.ts +++ b/src/hooks/useTheme.ts @@ -1,15 +1,26 @@ import { type Theme } from "@/contexts/AppContext"; import { useAppContext } from "@/hooks/useAppContext"; +import { useSystemTheme } from "./useSystemTheme"; /** * Hook to get and set the active theme * @returns Theme context with theme and setTheme */ -export function useTheme(): { theme: Theme; setTheme: (theme: Theme) => void } { +export function useTheme(): { + theme: Theme; + systemTheme: "light" | "dark"; + displayTheme: "light" | "dark"; + setTheme: (theme: Theme) => void; +} { const { config, updateConfig } = useAppContext(); + const systemTheme = useSystemTheme(); + const displayTheme = config.theme === 'system' ? systemTheme : config.theme; + return { theme: config.theme, + systemTheme, + displayTheme, setTheme: (theme: Theme) => { updateConfig((currentConfig) => ({ ...currentConfig, diff --git a/src/index.css b/src/index.css index 0feb937c..8a6259b7 100644 --- a/src/index.css +++ b/src/index.css @@ -247,6 +247,10 @@ max-height: 100dvh; } + pre.shiki { + background-color: transparent !important; + } + /* Fallback for browsers that don't support dvh */ @supports not (height: 100dvh) { .h-dvh { diff --git a/src/pages/NotFound.tsx b/src/pages/NotFound.tsx index 85e429d4..987de499 100644 --- a/src/pages/NotFound.tsx +++ b/src/pages/NotFound.tsx @@ -18,11 +18,11 @@ const NotFound = () => { }, [location.pathname]); return ( -
+
diff --git a/src/pages/Preferences.tsx b/src/pages/Preferences.tsx new file mode 100644 index 00000000..a99d4e45 --- /dev/null +++ b/src/pages/Preferences.tsx @@ -0,0 +1,73 @@ +import { Settings2, ArrowLeft } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { ThemePicker } from "@/components/ThemePicker"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { Label } from "@/components/ui/label"; +import { useIsMobile } from "@/hooks/useIsMobile"; +import { useNavigate } from "react-router-dom"; + +export function Preferences() { + const isMobile = useIsMobile(); + const navigate = useNavigate(); + + return ( +
+ {isMobile && ( +
+ +
+

+ + Preferences +

+

+ Manage your general application preferences and appearance settings. +

+
+
+ )} + + {!isMobile && ( +
+

+ + Preferences +

+

+ Manage your general application preferences and appearance settings. +

+
+ )} + + + + Appearance + + Customize how the application looks and feels. + + + +
+ +
+ +
+

+ Choose between light, dark, or system theme preference. +

+
+
+
+
+ ); +} + +export default Preferences; \ No newline at end of file diff --git a/src/pages/Settings.tsx b/src/pages/Settings.tsx index cff1c07e..5e9f3431 100644 --- a/src/pages/Settings.tsx +++ b/src/pages/Settings.tsx @@ -1,5 +1,5 @@ import { useNavigate } from 'react-router-dom'; -import { Bot, GitBranch, Database, Wifi } from 'lucide-react'; +import { Bot, GitBranch, Database, Wifi, Settings2 } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; interface SettingsItem { @@ -11,6 +11,13 @@ interface SettingsItem { } const settingsItems: SettingsItem[] = [ + { + id: 'preferences', + title: 'Preferences', + description: 'General application preferences and appearance', + icon: Settings2, + href: '/settings/preferences', + }, { id: 'ai', title: 'AI Settings',