mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(themes): apply OpenCode color themes app-wide with a settings picker (#364)
- Vendor the 36 OpenCode theme palettes into the shared package, synced from the pinned OpenCode release tag via pnpm themes:sync. - Add a colorTheme user preference across the settings schema, defaults, and the assistant internal API. - Extend palettes with success, warning, info, and diff colors, and add a resolver that maps palettes to CSS tokens and applies them to the DOM. - Apply the theme app-wide through a ThemeProvider context, adopting the tokens in message, repo, session, and settings components, agent colors, git status styles, and diff viewers. - Add a theme picker to General settings and make model quick-select follow the active theme (fixes #355).
This commit is contained in:
1 parent
702e3c4e13
commit
5bd688de4b
116 files changed
+2702
-760
No files matched your search
@@ -148,7 +148,7 @@ export function AccountSettings() {
|
||||
)}
|
||||
|
||||
{success && (
|
||||
<Alert className="border-green-500 text-green-700 dark:text-green-400">
|
||||
<Alert className="border-success text-success">
|
||||
<CheckCircle className="h-4 w-4" />
|
||||
<AlertDescription>{success}</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
@@ -84,7 +84,7 @@ export function AgentsMdEditor() {
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-8 text-red-500">
|
||||
<div className="text-center py-8 text-destructive">
|
||||
Failed to load AGENTS.md
|
||||
</div>
|
||||
)
|
||||
@@ -155,7 +155,7 @@ export function AgentsMdEditor() {
|
||||
</div>
|
||||
|
||||
{hasChanges && (
|
||||
<p className="text-xs text-amber-500">You have unsaved changes</p>
|
||||
<p className="text-xs text-warning">You have unsaved changes</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useSettings } from '@/hooks/useSettings'
|
||||
import { useVersionCheck } from '@/hooks/useVersionCheck'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import type { VersionInfo } from '@/api/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/hooks/useSettings')
|
||||
vi.mock('@/hooks/useVersionCheck')
|
||||
@@ -31,18 +32,7 @@ const baseVersionInfo: VersionInfo = {
|
||||
}
|
||||
|
||||
function mockUseSettings(overrides: Partial<ReturnType<typeof useSettings>> = {}) {
|
||||
vi.mocked(useSettings).mockReturnValue({
|
||||
settings: undefined,
|
||||
preferences: basePreferences,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
updateSettings: vi.fn(),
|
||||
updateSettingsAsync: vi.fn(),
|
||||
resetSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
isResetting: false,
|
||||
...overrides,
|
||||
})
|
||||
vi.mocked(useSettings).mockReturnValue(createUseSettingsMock({ preferences: basePreferences, ...overrides }))
|
||||
}
|
||||
|
||||
function mockVersionInfo(overrides: Partial<VersionInfo> = {}) {
|
||||
@@ -73,7 +63,7 @@ describe('GeneralSettings', () => {
|
||||
expect(screen.getByText('v1.2.3')).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'v1.3.0 available' })).toHaveAttribute('href', 'https://example.com/release')
|
||||
|
||||
expect(screen.getByLabelText('Theme')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Appearance')).toBeInTheDocument()
|
||||
expect(screen.getByRole('switch', { name: 'Simple chat mode' })).not.toBeChecked()
|
||||
expect(screen.getByRole('switch', { name: 'Auto-scroll' })).toBeChecked()
|
||||
expect(screen.getByRole('switch', { name: 'Show reasoning' })).not.toBeChecked()
|
||||
@@ -88,7 +78,7 @@ describe('GeneralSettings', () => {
|
||||
mockVersionInfo()
|
||||
render(<GeneralSettings />)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Theme' }))
|
||||
await user.click(screen.getByRole('combobox', { name: 'Appearance' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Light' }))
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({ theme: 'light' })
|
||||
@@ -97,6 +87,23 @@ describe('GeneralSettings', () => {
|
||||
expect(updateSettings).toHaveBeenCalledWith({ autoScroll: false })
|
||||
})
|
||||
|
||||
it('defaults the color theme to Manager and persists a chosen OpenCode theme', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({ updateSettings })
|
||||
mockVersionInfo()
|
||||
render(<GeneralSettings />)
|
||||
|
||||
expect(screen.getByRole('combobox', { name: 'Theme' })).toHaveTextContent('Manager')
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Theme' }))
|
||||
expect(screen.getByRole('option', { name: 'Manager' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('option', { name: 'OpenCode' })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('option', { name: 'Dracula' }))
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({ colorTheme: 'dracula' })
|
||||
})
|
||||
|
||||
it('hides the reasoning, tool call, and diff rows while simple chat mode is on', () => {
|
||||
mockUseSettings({ preferences: { ...basePreferences, simpleChatMode: true } })
|
||||
mockVersionInfo()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useVersionCheck } from '@/hooks/useVersionCheck'
|
||||
import { MANAGER_COLOR_THEME_ID, OPENCODE_THEMES, isColorThemeId } from '@opencode-manager/shared/themes'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
@@ -35,7 +36,7 @@ export function GeneralSettings() {
|
||||
href={versionInfo.releaseUrl ?? ''}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-xs font-medium text-green-500 hover:text-green-400 transition-colors"
|
||||
className="text-xs font-medium text-success hover:text-success/80 transition-colors"
|
||||
>
|
||||
v{versionInfo.latestVersion} available
|
||||
</a>
|
||||
@@ -49,16 +50,16 @@ export function GeneralSettings() {
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="theme">Theme</Label>
|
||||
<Label htmlFor="appearance">Appearance</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Choose your preferred color scheme
|
||||
Choose light, dark, or follow your system
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={preferences?.theme || 'dark'}
|
||||
onValueChange={(value) => updateSettings({ theme: value as 'dark' | 'light' | 'system' })}
|
||||
>
|
||||
<SelectTrigger id="theme" className="w-full shrink-0 sm:w-40">
|
||||
<SelectTrigger id="appearance" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a theme" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@@ -69,6 +70,33 @@ export function GeneralSettings() {
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="colorTheme">Theme</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use the Manager palette or an OpenCode theme
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={preferences?.colorTheme ?? MANAGER_COLOR_THEME_ID}
|
||||
onValueChange={(value) => {
|
||||
if (isColorThemeId(value)) updateSettings({ colorTheme: value })
|
||||
}}
|
||||
>
|
||||
<SelectTrigger id="colorTheme" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a theme" />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="max-h-80">
|
||||
<SelectItem value={MANAGER_COLOR_THEME_ID}>Manager</SelectItem>
|
||||
{OPENCODE_THEMES.map((theme) => (
|
||||
<SelectItem key={theme.id} value={theme.id}>
|
||||
{theme.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-border">
|
||||
<div className="flex items-start justify-between gap-4 py-3">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
|
||||
@@ -33,7 +33,7 @@ const SOURCE_OPTIONS: Array<{ value: SourceFilter; label: string }> = [
|
||||
|
||||
const LEVEL_CHIP_CLASSES: Record<ManagerLogLevel, string> = {
|
||||
error: 'bg-destructive/15 text-destructive',
|
||||
warn: 'bg-amber-500/15 text-amber-600 dark:text-amber-400',
|
||||
warn: 'bg-warning/15 text-warning',
|
||||
info: 'bg-accent text-accent-foreground',
|
||||
debug: 'bg-muted text-muted-foreground',
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export function ManagerTokenSettings({ isOpen: controlledOpen, onToggle }: Manag
|
||||
onClick={handleCopy}
|
||||
disabled={!token}
|
||||
>
|
||||
{copied ? <Check className="h-4 w-4 text-green-500" /> : <Copy className="h-4 w-4" />}
|
||||
{copied ? <Check className="h-4 w-4 text-success" /> : <Copy className="h-4 w-4" />}
|
||||
</Button>
|
||||
<Button
|
||||
variant={confirmRotate ? 'destructive' : 'outline'}
|
||||
|
||||
@@ -263,7 +263,7 @@ export function McpOAuthDialog({
|
||||
{step === 'waiting' && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-center py-4">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-blue-500" />
|
||||
<Loader2 className="h-5 w-5 animate-spin text-primary" />
|
||||
<span className="ml-2 text-sm text-muted-foreground">Waiting for authorization...</span>
|
||||
</div>
|
||||
<p className="text-xs text-center text-muted-foreground">
|
||||
@@ -287,7 +287,7 @@ export function McpOAuthDialog({
|
||||
|
||||
{step === 'popup_closed' && (
|
||||
<div className="flex flex-col items-center justify-center py-6 gap-2">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-blue-500" />
|
||||
<Loader2 className="h-5 w-5 animate-spin text-primary" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Checking authentication status...
|
||||
</p>
|
||||
@@ -307,7 +307,7 @@ export function McpOAuthDialog({
|
||||
|
||||
{step === 'success' && (
|
||||
<div className="flex flex-col items-center justify-center py-6 gap-2">
|
||||
<CheckCircle className="h-8 w-8 text-green-500" />
|
||||
<CheckCircle className="h-8 w-8 text-success" />
|
||||
<p className="text-sm font-medium">Authentication successful</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -91,7 +91,7 @@ export function McpServerCard({
|
||||
}
|
||||
description={getServerDescription(serverConfig)}
|
||||
belowDescription={errorMessage ? (
|
||||
<div className="flex items-start gap-1.5 mt-1.5 text-xs text-red-500">
|
||||
<div className="flex items-start gap-1.5 mt-1.5 text-xs text-destructive">
|
||||
<XCircle className="h-3 w-3 flex-shrink-0 mt-0.5" />
|
||||
<span className="break-words line-clamp-2">{errorMessage}</span>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ interface McpStatusBadgeProps {
|
||||
export function McpStatusBadge({ status }: McpStatusBadgeProps) {
|
||||
switch (status.status) {
|
||||
case 'connected':
|
||||
return <Badge variant="default" className="text-xs bg-green-600">Connected</Badge>
|
||||
return <Badge variant="default" className="text-xs bg-success text-success-foreground">Connected</Badge>
|
||||
case 'pending':
|
||||
return <Badge variant="outline" className="text-xs">Connecting</Badge>
|
||||
case 'disabled':
|
||||
@@ -23,7 +23,7 @@ export function McpStatusBadge({ status }: McpStatusBadgeProps) {
|
||||
)
|
||||
case 'needs_auth':
|
||||
return (
|
||||
<Badge variant="outline" className="text-xs flex items-center gap-1 border-yellow-500 text-yellow-600">
|
||||
<Badge variant="outline" className="text-xs flex items-center gap-1 border-warning text-warning">
|
||||
<Key className="h-3 w-3" />
|
||||
Auth Required
|
||||
</Badge>
|
||||
|
||||
@@ -63,7 +63,7 @@ export function NotificationSettings() {
|
||||
<h2 className="text-lg font-semibold text-foreground mb-4">
|
||||
Push Notifications
|
||||
</h2>
|
||||
<div className="flex items-center gap-3 text-yellow-500">
|
||||
<div className="flex items-center gap-3 text-warning">
|
||||
<BellOff className="h-5 w-5" />
|
||||
<p className="text-sm">
|
||||
Notification permission was denied. Please enable notifications in
|
||||
|
||||
@@ -280,7 +280,7 @@ export function OpenCodeConfigEditor({
|
||||
|
||||
{editError && (
|
||||
<div className="max-h-40 shrink-0 space-y-2 overflow-y-auto border-t bg-background p-3">
|
||||
<p className="break-words text-xs text-red-500 sm:text-sm">
|
||||
<p className="break-words text-xs text-destructive sm:text-sm">
|
||||
{editError}
|
||||
{editErrorLine != null && (
|
||||
<button
|
||||
@@ -293,7 +293,7 @@ export function OpenCodeConfigEditor({
|
||||
)}
|
||||
</p>
|
||||
{validationIssues.length > 0 && (
|
||||
<ul className="max-h-28 space-y-1 pl-4 text-xs text-red-500 list-disc sm:text-sm">
|
||||
<ul className="max-h-28 space-y-1 pl-4 text-xs text-destructive list-disc sm:text-sm">
|
||||
{validationIssues.map((issue) => (
|
||||
<li key={getIssueText(issue)}>
|
||||
{issue.line != null ? (
|
||||
|
||||
@@ -206,9 +206,9 @@ export function OpenCodeConfigManager() {
|
||||
return (
|
||||
<div className="min-w-0 space-y-4">
|
||||
{health?.opencodeRestartPending && (
|
||||
<div className="flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex flex-col gap-2 rounded-md border border-warning/40 bg-warning/10 p-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertTriangle className="h-4 w-4 shrink-0 text-amber-500" />
|
||||
<AlertTriangle className="h-4 w-4 shrink-0 text-warning" />
|
||||
<p className="text-sm">
|
||||
Some saved changes require a server restart to take effect.
|
||||
</p>
|
||||
@@ -242,7 +242,7 @@ export function OpenCodeConfigManager() {
|
||||
<>
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex min-w-0 items-start gap-2">
|
||||
<FileText className="mt-0.5 h-4 w-4 shrink-0 text-blue-500" />
|
||||
<FileText className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-sm font-medium">{getConfigFileName(config.path)}</p>
|
||||
<details className="text-xs text-muted-foreground">
|
||||
@@ -332,14 +332,14 @@ export function OpenCodeConfigManager() {
|
||||
onClick={() => toggleSection('agentsMd', agentsMdRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<FileText className="h-4 w-4 shrink-0 text-blue-500" />
|
||||
<FileText className="h-4 w-4 shrink-0 text-primary" />
|
||||
<div className="min-w-0 text-left">
|
||||
<h4 className="text-sm font-medium">Global Agent Instructions (AGENTS.md)</h4>
|
||||
<p className={SECTION_META_CLASS}>Applies across OpenCode</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-3">
|
||||
<span className="text-xs font-medium text-blue-500">Edit AGENTS.md</span>
|
||||
<span className="text-xs font-medium text-primary">Edit AGENTS.md</span>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.agentsMd && 'rotate-180')} />
|
||||
</div>
|
||||
</button>
|
||||
@@ -528,7 +528,7 @@ export function OpenCodeConfigManager() {
|
||||
onClick={() => toggleSection('hostImport', hostImportRef)}
|
||||
>
|
||||
<div className="flex min-w-0 items-center gap-3">
|
||||
<Download className="h-4 w-4 shrink-0 text-blue-500" />
|
||||
<Download className="h-4 w-4 shrink-0 text-primary" />
|
||||
<h4 className={SECTION_TITLE_CLASS}>Existing OpenCode Host Import</h4>
|
||||
</div>
|
||||
<ChevronDown className={cn(SECTION_CHEVRON_CLASS, expandedSections.hostImport && 'rotate-180')} />
|
||||
@@ -582,7 +582,7 @@ export function OpenCodeConfigManager() {
|
||||
</div>
|
||||
</div>
|
||||
{!isImportStatusLoading && workspaceConfigPathsToRemove.length > 0 && (
|
||||
<p className="flex items-start gap-2 text-xs text-amber-600 dark:text-amber-500">
|
||||
<p className="flex items-start gap-2 text-xs text-warning">
|
||||
<AlertTriangle className="mt-0.5 h-3.5 w-3.5 shrink-0" />
|
||||
<span>
|
||||
Importing replaces the workspace configuration files. These files will be removed:{' '}
|
||||
|
||||
@@ -23,12 +23,12 @@ export function OpenCodeConfigSourcesNotice({ config, targetName }: OpenCodeConf
|
||||
if (!writeTargetName) return null
|
||||
|
||||
return (
|
||||
<Alert className="border-blue-500/30 bg-blue-500/5">
|
||||
<Info className="h-4 w-4 text-blue-500" />
|
||||
<Alert className="border-info/30 bg-info/5">
|
||||
<Info className="h-4 w-4 text-info" />
|
||||
<details className="group" open>
|
||||
<summary className="flex cursor-pointer list-none items-center justify-between gap-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 [&::-webkit-details-marker]:hidden">
|
||||
<AlertTitle className="mb-0">Multiple configuration files are merged</AlertTitle>
|
||||
<ChevronDown className="h-4 w-4 shrink-0 text-blue-500 transition-transform group-open:rotate-180" />
|
||||
<ChevronDown className="h-4 w-4 shrink-0 text-info transition-transform group-open:rotate-180" />
|
||||
</summary>
|
||||
<AlertDescription>
|
||||
<p>
|
||||
|
||||
@@ -36,8 +36,8 @@ export function OpenCodeServerAuthSettings({ isOpen: controlledOpen, onToggle }:
|
||||
|
||||
const getStatusIcon = () => {
|
||||
if (!status) return null
|
||||
if (status.source === 'db') return <CheckCircle2 className="h-4 w-4 text-green-500" />
|
||||
if (status.source === 'env') return <CheckCircle2 className="h-4 w-4 text-blue-500" />
|
||||
if (status.source === 'db') return <CheckCircle2 className="h-4 w-4 text-success" />
|
||||
if (status.source === 'env') return <CheckCircle2 className="h-4 w-4 text-info" />
|
||||
return <CheckCircle2 className="h-4 w-4 text-muted-foreground" />
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,7 @@ export function ProviderSettings() {
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{hasKey ? (
|
||||
<Badge variant="default" className="bg-green-600 hover:bg-green-700 shrink-0">
|
||||
<Badge variant="default" className="bg-success text-success-foreground hover:bg-success/90 shrink-0">
|
||||
<Check className="h-3 w-3 mr-1" />
|
||||
Connected
|
||||
</Badge>
|
||||
@@ -304,7 +304,7 @@ export function ProviderSettings() {
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Badge variant="default" className="bg-green-600 hover:bg-green-700 shrink-0 text-xs">
|
||||
<Badge variant="default" className="bg-success text-success-foreground hover:bg-success/90 shrink-0 text-xs">
|
||||
<Check className="h-3 w-3 mr-1" />
|
||||
Connected
|
||||
</Badge>
|
||||
|
||||
@@ -183,12 +183,12 @@ export function STTSettings() {
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
{saveStatus === 'saved' && (
|
||||
<>
|
||||
<CheckCircle2 className="h-4 w-4 text-green-500" />
|
||||
<span className="text-green-600">Saved</span>
|
||||
<CheckCircle2 className="h-4 w-4 text-success" />
|
||||
<span className="text-success">Saved</span>
|
||||
</>
|
||||
)}
|
||||
{saveStatus === 'idle' && isDirty && isValid && (
|
||||
<span className="text-amber-600">Unsaved changes</span>
|
||||
<span className="text-warning">Unsaved changes</span>
|
||||
)}
|
||||
{saveStatus === 'idle' && !isDirty && (
|
||||
<span className="text-muted-foreground">All changes saved</span>
|
||||
@@ -379,8 +379,8 @@ export function STTSettings() {
|
||||
)}
|
||||
|
||||
{sttError && (
|
||||
<div className="rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 p-4">
|
||||
<div className="text-sm text-amber-800 dark:text-amber-200 flex items-start gap-2">
|
||||
<div className="rounded-lg bg-warning/10 border border-warning/20 p-4">
|
||||
<div className="text-sm text-warning flex items-start gap-2">
|
||||
<XCircle className="h-4 w-4 mt-0.5 shrink-0" />
|
||||
<div>{sttError}</div>
|
||||
</div>
|
||||
@@ -414,19 +414,19 @@ export function STTSettings() {
|
||||
</div>
|
||||
)}
|
||||
{!isTesting && !isProcessing && testResult === 'success' && testTranscript && (
|
||||
<div className="mt-2 p-2 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded max-h-24 overflow-y-auto">
|
||||
<div className="mt-2 p-2 bg-success/10 border border-success/20 rounded max-h-24 overflow-y-auto">
|
||||
<div className="flex items-center gap-1 mb-1">
|
||||
<CheckCircle2 className="h-3 w-3 text-green-600 dark:text-green-400" />
|
||||
<span className="text-xs font-medium text-green-700 dark:text-green-300">Test successful</span>
|
||||
<CheckCircle2 className="h-3 w-3 text-success" />
|
||||
<span className="text-xs font-medium text-success">Test successful</span>
|
||||
</div>
|
||||
<p className="text-sm text-green-800 dark:text-green-200">{testTranscript}</p>
|
||||
<p className="text-sm text-success">{testTranscript}</p>
|
||||
</div>
|
||||
)}
|
||||
{!isTesting && !isProcessing && testResult === 'failed' && (
|
||||
<div className="mt-2 p-2 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded">
|
||||
<div className="mt-2 p-2 bg-destructive/10 border border-destructive/20 rounded">
|
||||
<div className="flex items-center gap-1">
|
||||
<XCircle className="h-3 w-3 text-red-600 dark:text-red-400" />
|
||||
<span className="text-xs font-medium text-red-700 dark:text-red-300">Test failed - {sttError || 'no speech detected'}</span>
|
||||
<XCircle className="h-3 w-3 text-destructive" />
|
||||
<span className="text-xs font-medium text-destructive">Test failed - {sttError || 'no speech detected'}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -439,7 +439,7 @@ export function STTSettings() {
|
||||
!canTest && !isRecording && !isProcessing
|
||||
? 'bg-muted text-muted-foreground cursor-not-allowed'
|
||||
: isRecording
|
||||
? 'bg-gradient-to-br from-red-600 to-red-700 hover:from-red-500 hover:to-red-600 text-destructive-foreground border-2 border-red-500/60 shadow-lg shadow-red-500/30'
|
||||
? 'bg-destructive hover:bg-destructive/90 text-destructive-foreground border-2 border-destructive/60 shadow-lg shadow-destructive/30'
|
||||
: isProcessing
|
||||
? 'bg-muted text-muted-foreground cursor-wait'
|
||||
: 'bg-primary hover:bg-primary/90 text-primary-foreground'
|
||||
|
||||
@@ -6,6 +6,8 @@ import { useSettings } from '@/hooks/useSettings'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { FetchError } from '@/api/fetchWrapper'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/hooks/useSettings')
|
||||
vi.mock('@/hooks/useServerHealth')
|
||||
@@ -15,18 +17,13 @@ vi.mock('@/lib/toast', () => ({
|
||||
|
||||
function mockUseSettings(overrides: Partial<ReturnType<typeof useSettings>> = {}) {
|
||||
const updateSettingsAsync = vi.fn().mockResolvedValue(undefined)
|
||||
vi.mocked(useSettings).mockReturnValue({
|
||||
settings: undefined,
|
||||
preferences: { sandbox: { enabled: false } },
|
||||
isLoading: false,
|
||||
error: null,
|
||||
updateSettings: vi.fn(),
|
||||
updateSettingsAsync,
|
||||
resetSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
isResetting: false,
|
||||
...overrides,
|
||||
})
|
||||
vi.mocked(useSettings).mockReturnValue(
|
||||
createUseSettingsMock({
|
||||
preferences: { sandbox: { enabled: false } } as UserPreferences,
|
||||
updateSettingsAsync,
|
||||
...overrides,
|
||||
}),
|
||||
)
|
||||
return { updateSettingsAsync }
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { ServerEnvVarsSettings } from './ServerEnvVarsSettings'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
updateSettingsAsync: vi.fn(),
|
||||
@@ -13,17 +15,12 @@ vi.mock('@/hooks/useSettings')
|
||||
vi.mock('@/lib/toast', () => ({ showToast: mocks.showToast }))
|
||||
|
||||
function mockSettings(serverEnvVars: Array<{ key: string; value: string }> = []): void {
|
||||
vi.mocked(useSettings).mockReturnValue({
|
||||
settings: undefined,
|
||||
preferences: { serverEnvVars },
|
||||
isLoading: false,
|
||||
error: null,
|
||||
updateSettings: vi.fn(),
|
||||
updateSettingsAsync: mocks.updateSettingsAsync,
|
||||
resetSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
isResetting: false,
|
||||
} as ReturnType<typeof useSettings>)
|
||||
vi.mocked(useSettings).mockReturnValue(
|
||||
createUseSettingsMock({
|
||||
preferences: { serverEnvVars } as UserPreferences,
|
||||
updateSettingsAsync: mocks.updateSettingsAsync,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
describe('ServerEnvVarsSettings', () => {
|
||||
|
||||
@@ -36,7 +36,7 @@ export function ServerHealthStatus({ onOpenVersionDialog }: ServerHealthStatusPr
|
||||
<>
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<div className={`h-3 w-3 rounded-full ${isUnhealthy ? 'bg-destructive animate-pulse' : 'bg-green-500'}`} />
|
||||
<div className={`h-3 w-3 rounded-full ${isUnhealthy ? 'bg-destructive animate-pulse' : 'bg-success'}`} />
|
||||
<p className="font-medium text-sm">
|
||||
Server Status: {isUnhealthy ? 'Unhealthy' : 'Healthy'}
|
||||
</p>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { render, screen, fireEvent, within, act } from '@testing-library/react'
|
||||
import { MemoryRouter, useLocation, useNavigate } from 'react-router-dom'
|
||||
import { SettingsDialog } from './SettingsDialog'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { DESKTOP_MEDIA_QUERY } from '@/hooks/useMediaQuery'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/components/settings/GeneralSettings', () => ({
|
||||
GeneralSettings: () => <div data-testid="general-settings">General Settings Content</div>,
|
||||
@@ -53,27 +53,6 @@ vi.mock('@/hooks/useMobile', () => ({
|
||||
})),
|
||||
}))
|
||||
|
||||
function stubMatchMedia(matches: boolean): () => void {
|
||||
const listeners = new Set<() => void>()
|
||||
const mediaQueryList = {
|
||||
media: DESKTOP_MEDIA_QUERY,
|
||||
matches,
|
||||
addEventListener: (_type: string, listener: () => void) => {
|
||||
listeners.add(listener)
|
||||
},
|
||||
removeEventListener: (_type: string, listener: () => void) => {
|
||||
listeners.delete(listener)
|
||||
},
|
||||
}
|
||||
const original = window.matchMedia
|
||||
void original
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: () => mediaQueryList,
|
||||
})
|
||||
}
|
||||
|
||||
describe('SettingsDialog', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
@@ -233,7 +233,7 @@ export function SettingsDialog() {
|
||||
>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="p-3 bg-accent rounded-lg">
|
||||
<item.icon className="w-6 h-6 text-blue-600 dark:text-blue-400" />
|
||||
<item.icon className="w-6 h-6 text-primary" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="font-semibold text-foreground mb-1">{item.label}</h3>
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { ManagerLogEntry } from '@opencode-manager/shared/schemas'
|
||||
import { SettingsDialog } from './SettingsDialog'
|
||||
import { logsApi } from '@/api/logs'
|
||||
import { DEFAULTS } from '@/config'
|
||||
import { DESKTOP_MEDIA_QUERY } from '@/hooks/useMediaQuery'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/api/logs', () => ({
|
||||
logsApi: {
|
||||
@@ -48,25 +48,6 @@ function makeResponse(entries: ManagerLogEntry[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function stubMatchMedia(matches: boolean): void {
|
||||
const listeners = new Set<() => void>()
|
||||
const mediaQueryList = {
|
||||
media: DESKTOP_MEDIA_QUERY,
|
||||
matches,
|
||||
addEventListener: (_type: string, listener: () => void) => {
|
||||
listeners.add(listener)
|
||||
},
|
||||
removeEventListener: (_type: string, listener: () => void) => {
|
||||
listeners.delete(listener)
|
||||
},
|
||||
}
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: () => mediaQueryList,
|
||||
})
|
||||
}
|
||||
|
||||
function createWrapper() {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
|
||||
@@ -254,12 +254,12 @@ export function TTSSettings() {
|
||||
)}
|
||||
{saveStatus === 'saved' && (
|
||||
<>
|
||||
<CheckCircle2 className="h-4 w-4 text-green-500" />
|
||||
<span className="text-green-600">Saved</span>
|
||||
<CheckCircle2 className="h-4 w-4 text-success" />
|
||||
<span className="text-success">Saved</span>
|
||||
</>
|
||||
)}
|
||||
{saveStatus === 'idle' && isDirty && isValid && (
|
||||
<span className="text-amber-600">Unsaved changes</span>
|
||||
<span className="text-warning">Unsaved changes</span>
|
||||
)}
|
||||
{saveStatus === 'idle' && !isDirty && (
|
||||
<span className="text-muted-foreground">All changes saved</span>
|
||||
@@ -325,12 +325,12 @@ export function TTSSettings() {
|
||||
}}
|
||||
className={`flex flex-col items-center justify-center gap-2 rounded-lg border-2 p-4 transition ${
|
||||
watchProvider === 'builtin'
|
||||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/20'
|
||||
: 'border-border hover:border-blue-300'
|
||||
? 'border-primary bg-primary/10'
|
||||
: 'border-border hover:border-primary/50'
|
||||
}`}
|
||||
>
|
||||
<MonitorSpeaker className={`h-6 w-6 ${watchProvider === 'builtin' ? 'text-blue-600 dark:text-blue-400' : 'text-muted-foreground'}`} />
|
||||
<span className={`font-medium ${watchProvider === 'builtin' ? 'text-blue-700 dark:text-blue-300' : ''}`}>
|
||||
<MonitorSpeaker className={`h-6 w-6 ${watchProvider === 'builtin' ? 'text-primary' : 'text-muted-foreground'}`} />
|
||||
<span className={`font-medium ${watchProvider === 'builtin' ? 'text-primary' : ''}`}>
|
||||
Built-in Browser
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground text-center">
|
||||
@@ -344,12 +344,12 @@ export function TTSSettings() {
|
||||
}}
|
||||
className={`flex flex-col items-center justify-center gap-2 rounded-lg border-2 p-4 transition ${
|
||||
watchProvider === 'external'
|
||||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/20'
|
||||
: 'border-border hover:border-blue-300'
|
||||
? 'border-primary bg-primary/10'
|
||||
: 'border-border hover:border-primary/50'
|
||||
}`}
|
||||
>
|
||||
<Globe className={`h-6 w-6 ${watchProvider === 'external' ? 'text-blue-600 dark:text-blue-400' : 'text-muted-foreground'}`} />
|
||||
<span className={`font-medium ${watchProvider === 'external' ? 'text-blue-700 dark:text-blue-300' : ''}`}>
|
||||
<Globe className={`h-6 w-6 ${watchProvider === 'external' ? 'text-primary' : 'text-muted-foreground'}`} />
|
||||
<span className={`font-medium ${watchProvider === 'external' ? 'text-primary' : ''}`}>
|
||||
External API
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground text-center">
|
||||
@@ -565,8 +565,8 @@ export function TTSSettings() {
|
||||
/>
|
||||
|
||||
{!hasWebSpeechSupport && (
|
||||
<div className="rounded-lg bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 p-4">
|
||||
<div className="text-sm text-yellow-800 dark:text-yellow-200">
|
||||
<div className="rounded-lg bg-warning/10 border border-warning/20 p-4">
|
||||
<div className="text-sm text-warning">
|
||||
<strong>Browser Not Supported</strong>: Your browser doesn't support Web Speech API.
|
||||
Please use Chrome, Safari, Firefox, or Edge, or switch to an external API provider.
|
||||
</div>
|
||||
|
||||
@@ -84,7 +84,7 @@ export function VersionSelectDialog({ open, onOpenChange }: VersionSelectDialogP
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="text-center py-8 text-red-500">
|
||||
<div className="text-center py-8 text-destructive">
|
||||
Failed to fetch versions
|
||||
</div>
|
||||
)}
|
||||
@@ -106,7 +106,7 @@ export function VersionSelectDialog({ open, onOpenChange }: VersionSelectDialogP
|
||||
isSelected
|
||||
? 'border-primary bg-primary/10'
|
||||
: isCurrent
|
||||
? 'border-green-500/50 bg-green-500/10 cursor-default'
|
||||
? 'border-success/50 bg-success/10 cursor-default'
|
||||
: 'border-border hover:border-primary/50 hover:bg-muted/50'
|
||||
}`}
|
||||
>
|
||||
@@ -115,7 +115,7 @@ export function VersionSelectDialog({ open, onOpenChange }: VersionSelectDialogP
|
||||
<div className="font-medium flex items-center gap-2">
|
||||
v{release.version}
|
||||
{isCurrent && (
|
||||
<span className="text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-600 dark:text-green-400">
|
||||
<span className="text-xs px-1.5 py-0.5 rounded bg-success/20 text-success">
|
||||
Current
|
||||
</span>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user