feat(frontend): default site theme to Amber instead of Classic

New visitors (no saved lv_theme) now get the Amber accent; reconciled the
static CSS accent, demo scene colors and console greeting to match so there
is no blue/emerald flash before the theme provider applies. Updated the
default-theme assertions in the theme tests.
This commit is contained in:
loki5512344 2026-09-29 10:55:18 +02:00
parent 8a758754dd
commit 3f679b83f6
Signed by: boba
GPG key ID: 253067914055423B
8 changed files with 16 additions and 12 deletions

View file

@ -36,6 +36,7 @@ test('a theme card inside the preview loads that preset into the draft, not the
await user.click(within(gui).getByRole('option', { name: 'Тема Nitro' }))
expect(screen.getByDisplayValue('Nitro')).toBeInTheDocument()
expect(within(gui).getByRole('option', { name: 'Тема Nitro' })).toHaveAttribute('aria-selected', 'true')
expect(screen.getByRole('status', { name: 'site theme' })).toHaveTextContent(PRESETS[0].id)
// The site keeps its default theme (amber) even though the draft loaded Classic.
expect(screen.getByRole('status', { name: 'site theme' })).toHaveTextContent('amber')
expect(window.localStorage.getItem('lv_theme')).toBeNull()
})

View file

@ -21,7 +21,7 @@ afterEach(() => {
test('a user pick persists to lv_theme, re-accents the page and locks out demo switches', () => {
render(<ActiveThemeProvider><Probe /></ActiveThemeProvider>)
expect(screen.getByTestId('id')).toHaveTextContent('classic')
expect(screen.getByTestId('id')).toHaveTextContent('amber')
act(() => screen.getByText('demo').click())
expect(screen.getByTestId('id')).toHaveTextContent('sunset')
expect(window.localStorage.getItem('lv_theme')).toBeNull()
@ -47,7 +47,7 @@ test('restores the stored theme and survives blocked storage', () => {
throw new Error('blocked')
})
render(<ActiveThemeProvider><Probe /></ActiveThemeProvider>)
expect(screen.getByTestId('id')).toHaveTextContent('classic')
expect(screen.getByTestId('id')).toHaveTextContent('amber')
act(() => screen.getByText('user').click())
expect(screen.getByTestId('id')).toHaveTextContent('nitro')
vi.restoreAllMocks()

View file

@ -3,7 +3,9 @@ import { PRESETS } from './presets.generated'
import { parseArgb, type ThemeEntry, withAlpha } from './types'
const STORAGE_KEY = 'lv_theme'
const FALLBACK = PRESETS[0]
// Amber is the site default for visitors who never picked a theme; Classic stays at PRESETS[0]
// (mirroring the mod's own default) and is only reached if the amber preset ever goes missing.
const FALLBACK = PRESETS.find((p) => p.id === 'amber') ?? PRESETS[0]
type ActiveTheme = {
theme: ThemeEntry
@ -66,7 +68,7 @@ export function ActiveThemeProvider({ children, applyToPage = true }: { children
return createElement(ActiveThemeContext.Provider, { value }, children)
}
/** The active ClickGui theme. Outside a provider it falls back to Classic with a no-op setter. */
/** The active ClickGui theme. Outside a provider it falls back to the default with a no-op setter. */
export function useActiveTheme(): ActiveTheme {
return useContext(ActiveThemeContext) ?? { theme: FALLBACK, userPicked: false, setTheme: () => {} }
}