mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Merge branch 'dark-mode' into 'main'
Dark Mode See merge request soapbox-pub/act2!17
This commit is contained in:
commit
6f399af544
12 files changed
+258
-50
No files matched your search
@@ -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() {
|
||||
<Route path="/oauth/github" element={<GitHubOAuth />} />
|
||||
<Route path="/settings" element={<SettingsLayout />}>
|
||||
<Route index element={<Settings />} />
|
||||
<Route path="preferences" element={<Preferences />} />
|
||||
<Route path="nostr" element={<NostrSettings />} />
|
||||
<Route path="ai" element={<AISettings />} />
|
||||
<Route path="git" element={<GitSettings />} />
|
||||
|
||||
@@ -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(({
|
||||
<Streamdown
|
||||
className='size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0'
|
||||
parseIncompleteMarkdown={isCurrentlyLoading}
|
||||
shikiTheme={displayTheme === 'dark' ? 'github-dark' : 'github-light'}
|
||||
>
|
||||
{getContent()}
|
||||
</Streamdown>
|
||||
|
||||
@@ -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<string, unknown>;
|
||||
return {
|
||||
...actual,
|
||||
useNavigate: () => vi.fn()
|
||||
};
|
||||
});
|
||||
vi.mock('@tanstack/react-query', async (importOriginal) => {
|
||||
const actual = await importOriginal() as Record<string, unknown>;
|
||||
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(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('🎭')).toBeInTheDocument();
|
||||
@@ -56,11 +68,13 @@ describe('ProjectSidebar', () => {
|
||||
const mockToggle = vi.fn();
|
||||
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
onToggleSidebar={mockToggle}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
onToggleSidebar={mockToggle}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
const collapseButton = screen.getByLabelText('Collapse sidebar');
|
||||
@@ -72,10 +86,12 @@ describe('ProjectSidebar', () => {
|
||||
|
||||
it('does not show collapse button when onToggleSidebar is not provided', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.queryByLabelText('Collapse sidebar')).not.toBeInTheDocument();
|
||||
@@ -83,10 +99,12 @@ describe('ProjectSidebar', () => {
|
||||
|
||||
it('renders settings and help buttons at the bottom', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument();
|
||||
@@ -95,10 +113,12 @@ describe('ProjectSidebar', () => {
|
||||
|
||||
it('shows new project button', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('New Project')).toBeInTheDocument();
|
||||
@@ -106,10 +126,12 @@ describe('ProjectSidebar', () => {
|
||||
|
||||
it('opens help documentation when help button is clicked', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
<TestApp>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
const helpButton = screen.getByLabelText('Help');
|
||||
|
||||
@@ -90,8 +90,8 @@ export function ProjectSidebar({
|
||||
const queryClient = useQueryClient();
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
const [favorites] = useLocalStorage<string[]>('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({
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="flex-1 h-9 justify-start gap-2 hover:bg-primary/10 text-sidebar-foreground"
|
||||
className="flex-1 h-9 justify-start gap-2 text-sidebar-foreground dark:hover:text-sidebar-primary hover:bg-sidebar-accent/50 dark:hover:bg-sidebar-accent/30 transition-all duration-200"
|
||||
onClick={() => navigateAndClose('/settings')}
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
<Settings className="h-4 w-4 transition-colors duration-200" />
|
||||
Settings
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-9 w-9 p-0 hover:bg-primary/10 text-sidebar-foreground"
|
||||
className="h-9 w-9 p-0 text-sidebar-foreground dark:hover:text-sidebar-primary hover:bg-sidebar-accent/50 dark:hover:bg-sidebar-accent/30 transition-all duration-200"
|
||||
onClick={() => window.open('https://soapbox.pub/shakespeare-resources/', '_blank')}
|
||||
aria-label="Help"
|
||||
>
|
||||
<HelpCircle className="h-4 w-4" />
|
||||
<HelpCircle className="h-4 w-4 transition-colors duration-200" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 (
|
||||
<div className="min-h-dvh bg-white">
|
||||
<div className="min-h-dvh bg-background">
|
||||
{/* Mobile Header */}
|
||||
<header className="h-12 border-b bg-white px-4 py-3 flex items-center justify-between">
|
||||
<header className="h-12 border-b bg-background px-4 py-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -145,7 +152,7 @@ export function SettingsLayout() {
|
||||
|
||||
// Desktop 3-column layout
|
||||
return (
|
||||
<div className="h-screen flex bg-white overflow-hidden">
|
||||
<div className="h-screen flex bg-background overflow-hidden">
|
||||
{/* Left Column - Projects Sidebar (optionally hidden) */}
|
||||
{isSidebarVisible && (
|
||||
<div className="w-80 border-r bg-sidebar flex-shrink-0">
|
||||
@@ -159,7 +166,7 @@ export function SettingsLayout() {
|
||||
)}
|
||||
|
||||
{/* Middle Column - Settings Navigation */}
|
||||
<div className="w-96 border-r bg-white flex flex-col flex-shrink-0">
|
||||
<div className="w-96 border-r bg-background flex flex-col flex-shrink-0">
|
||||
{/* Header with toggle button */}
|
||||
<div className="h-12 px-4 py-2 border-b flex-shrink-0">
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -217,7 +224,7 @@ export function SettingsLayout() {
|
||||
</div>
|
||||
|
||||
{/* Right Column - Settings Content - Scrollable */}
|
||||
<ScrollArea className="flex-1 bg-white">
|
||||
<ScrollArea className="flex-1 bg-background">
|
||||
<div className="max-w-4xl">
|
||||
<Outlet />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { ChevronsUpDown, Monitor, Moon, Sun } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { useTheme } from "@/hooks/useTheme";
|
||||
import { type Theme } from "@/contexts/AppContext";
|
||||
|
||||
export function ThemePicker() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
|
||||
const themeOptions: { value: Theme; label: string; icon: React.ComponentType<{ className?: string }> }[] = [
|
||||
{ value: "system", label: "System", icon: Monitor },
|
||||
{ value: "light", label: "Light", icon: Sun },
|
||||
{ value: "dark", label: "Dark", icon: Moon },
|
||||
];
|
||||
|
||||
const currentTheme = themeOptions.find(option => option.value === theme);
|
||||
const CurrentIcon = currentTheme?.icon || Monitor;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className="w-full justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<CurrentIcon className="h-4 w-4" />
|
||||
<span>{currentTheme?.label || "System"}</span>
|
||||
</div>
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-[180px]">
|
||||
{themeOptions.map((option) => {
|
||||
const Icon = option.icon;
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={option.value}
|
||||
onClick={() => setTheme(option.value)}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
<span>{option.label}</span>
|
||||
{theme === option.value && (
|
||||
<div className="ml-auto h-2 w-2 rounded-full bg-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+12
-1
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -18,11 +18,11 @@ const NotFound = () => {
|
||||
}, [location.pathname]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-100 dark:bg-gray-900">
|
||||
<div className="min-h-screen flex items-center justify-center bg-background">
|
||||
<div className="text-center">
|
||||
<h1 className="text-4xl font-bold mb-4 text-gray-900 dark:text-gray-100">404</h1>
|
||||
<p className="text-xl text-gray-600 dark:text-gray-400 mb-4">Oops! Page not found</p>
|
||||
<a href="/" className="text-blue-500 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300 underline">
|
||||
<h1 className="text-4xl font-bold mb-4 text-foreground">404</h1>
|
||||
<p className="text-xl text-muted-foreground mb-4">Oops! Page not found</p>
|
||||
<a href="/" className="text-primary hover:text-primary/80 underline">
|
||||
Return to Home
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -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 (
|
||||
<div className="p-6 space-y-6">
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
Back to Settings
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Settings2 className="h-6 w-6 text-primary" />
|
||||
Preferences
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your general application preferences and appearance settings.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Settings2 className="h-6 w-6 text-primary" />
|
||||
Preferences
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your general application preferences and appearance settings.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Appearance</CardTitle>
|
||||
<CardDescription>
|
||||
Customize how the application looks and feels.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="theme-picker">Theme</Label>
|
||||
<div className="w-full max-w-xs">
|
||||
<ThemePicker />
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Choose between light, dark, or system theme preference.
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Preferences;
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user