Commit b1407273 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Swap visual identity to shadcn preset b311momZs0 with real light/dark mode

Re-themes the whole app by bridging the existing cobalt token names in
src/index.css to shadcn's new CSS variables, rather than rewriting every
component. Adds ThemeContext + a Settings appearance toggle so .dark now
actually gets applied somewhere in the app - closing the token collision
where shadcn's --color-background/--color-primary/--color-secondary would
otherwise silently fall back to shadcn's light values next to an
all-dark app. Defaults new visitors to dark to match the app's prior
dark-only behavior. Self-hosts DM Sans/Outfit via @fontsource-variable
instead of the old Google Fonts link.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent c7c9043b
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-maia",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "mist",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"menuColor": "default",
"menuAccent": "subtle",
"registries": {}
}
......@@ -6,15 +6,35 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<meta name="theme-color" content="#131313" />
<meta name="theme-color" content="#0b0b10" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Stax" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="" />
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
<title>Stax</title>
<script>
// Applies the saved theme (or system preference, on first visit) before React mounts -
// ThemeProvider (src/context/ThemeContext.tsx) does the same resolution on every render,
// this just avoids a flash of the wrong theme between first paint and React hydrating.
// Stax has always been a dark app with no toggle until now (2026-10-07's shadcn swap), so
// a returning user with no saved preference and a light-mode OS still gets dark, not a
// surprise flip - only a genuinely new choice (explicit 'light', or 'system' once they've
// opted into it) can produce light mode.
(function () {
try {
var stored = localStorage.getItem('stax_theme')
var isDark =
stored === 'light'
? false
: stored === 'system'
? window.matchMedia('(prefers-color-scheme: dark)').matches
: true
document.documentElement.classList.toggle('dark', isDark)
} catch (e) {
document.documentElement.classList.add('dark')
}
})()
</script>
</head>
<body>
<div id="root"></div>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -12,13 +12,19 @@
"test:watch": "vitest"
},
"dependencies": {
"@base-ui/react": "^1.8.0",
"@fontsource-variable/dm-sans": "^5.3.0",
"@fontsource-variable/outfit": "^5.3.0",
"@vitejs/plugin-basic-ssl": "^2.3.0",
"class-variance-authority": "^0.7.1",
"cn": "^0.4.0",
"leaflet": "^1.9.4",
"lucide-react": "^1.31.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"react-leaflet": "^5.0.0",
"react-router-dom": "^7.18.2"
"react-router-dom": "^7.18.2",
"tw-animate-css": "^1.4.0"
},
"devDependencies": {
"@tailwindcss/vite": "^4.3.3",
......@@ -32,6 +38,7 @@
"@vitejs/plugin-react": "^6.0.4",
"jsdom": "^29.1.1",
"oxlint": "^1.75.0",
"shadcn": "^4.21.3",
"tailwindcss": "^4.3.3",
"typescript": "~6.0.2",
"vite": "^8.2.0",
......
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react'
export type ThemePreference = 'light' | 'dark' | 'system'
const STORAGE_KEY = 'stax_theme'
function resolveIsDark(pref: ThemePreference): boolean {
if (pref === 'system') return window.matchMedia('(prefers-color-scheme: dark)').matches
return pref === 'dark'
}
interface ThemeContextValue {
theme: ThemePreference
isDark: boolean
setTheme: (theme: ThemePreference) => void
}
const ThemeContext = createContext<ThemeContextValue | null>(null)
/** Stax has always been a dark-only app with no toggle until the 2026-10-07 shadcn swap - the
* blocking inline script in index.html already applies the right `.dark` class before React
* even mounts (avoiding a flash), and defaults a first-time visitor with no stored preference
* to dark rather than 'system', so a returning user on a light-mode OS doesn't get surprised by
* their familiar dark app suddenly turning white. This provider's own initial state has to
* agree with that same default, not re-derive it independently. */
export function ThemeProvider({ children }: { children: ReactNode }) {
const [theme, setThemeState] = useState<ThemePreference>(() => {
const stored = localStorage.getItem(STORAGE_KEY)
return stored === 'light' || stored === 'dark' || stored === 'system' ? stored : 'dark'
})
useEffect(() => {
document.documentElement.classList.toggle('dark', resolveIsDark(theme))
if (theme !== 'system') return
// Keeps following the OS live while "system" is selected, rather than only resolving once
// at mount - matches what picking "system" actually implies.
const mql = window.matchMedia('(prefers-color-scheme: dark)')
const onChange = () => document.documentElement.classList.toggle('dark', mql.matches)
mql.addEventListener('change', onChange)
return () => mql.removeEventListener('change', onChange)
}, [theme])
function setTheme(next: ThemePreference) {
localStorage.setItem(STORAGE_KEY, next)
setThemeState(next)
}
return (
<ThemeContext.Provider value={{ theme, isDark: resolveIsDark(theme), setTheme }}>
{children}
</ThemeContext.Provider>
)
}
export function useTheme(): ThemeContextValue {
const ctx = useContext(ThemeContext)
if (!ctx) throw new Error('useTheme must be used within a ThemeProvider')
return ctx
}
This diff is collapsed.
export { cn } from "cn"
......@@ -6,15 +6,18 @@ import './lib/leafletIcons'
import { App } from './App.tsx'
import { AuthProvider } from './context/AuthContext.tsx'
import { PlayerProvider } from './context/PlayerContext.tsx'
import { ThemeProvider } from './context/ThemeContext.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<BrowserRouter>
<AuthProvider>
<PlayerProvider>
<App />
</PlayerProvider>
</AuthProvider>
</BrowserRouter>
<ThemeProvider>
<BrowserRouter>
<AuthProvider>
<PlayerProvider>
<App />
</PlayerProvider>
</AuthProvider>
</BrowserRouter>
</ThemeProvider>
</StrictMode>,
)
......@@ -168,7 +168,10 @@ const FRONTEND_DONE: DoneGroup[] = [
{
area: 'Design System',
items: [
'Full visual redesign (2026-08-23), sourced from a Stitch design export: cobalt/periwinkle-on-deep-ink Material-3-style token system (primary #b8c3ff / primary-container #2e5bff on #131313), Space Grotesk, sharp 4px-radius geometry - deliberately not the export\'s mint-green "Stax" variant, which read too close to an existing music app\'s brand color',
'Second full visual redesign (2026-10-07): swapped onto a real shadcn/ui preset (style "maia", blue theme, DM Sans body / Outfit headings, large radius, Base UI primitives - `npx shadcn init --preset b311momZs0`) rather than the cobalt/Space-Grotesk system from 2026-08-23 below, after that one wasn\'t landing well. Done as a token bridge, not a per-component rewrite: every one of the ~40 existing Material-3-style token names (bg-surface-container-low, text-on-primary, etc.) stayed exactly as-is in every component file - only their underlying CSS values in src/index.css changed, from hardcoded hex to `var()` references into the shadcn preset\'s own :root/.dark variables. Zero page/component files touched; every existing page automatically re-themed for free. A few tokens have no direct shadcn equivalent (no "hover-lightened primary" token exists) - those use `color-mix()` against the nearest real token instead of a new hardcoded color that wouldn\'t track light/dark. Border radius needed no bridging at all: the app never overrode Tailwind\'s stock rounded-* scale, so shadcn\'s own --radius-* tokens (which directly define rounded-sm/md/lg/xl/etc.) applied cleanly with zero collision the moment they were defined.',
'Real light/dark mode (2026-10-07), the app\'s first - previously deliberately dark-only with no toggle at all, which is exactly why plugging in the shadcn preset directly (its CSS defines genuinely different light vs. dark values) would have silently broken without this: the preset\'s `.dark` class was never applied anywhere, so background/primary/secondary would have resolved to its light-mode values sitting next to the rest of the still-dark-styled app. New ThemeContext (light/dark/system, persisted to localStorage) toggles `.dark` on <html>; a blocking inline script in index.html applies the right class before React even mounts, avoiding a flash - and defaults a first-time visitor with no stored preference to dark specifically (not "system"), so a returning user on a light-mode OS doesn\'t get surprised by their familiar dark app turning white. New "Appearance" segmented control (Light/Dark/System) on the Settings page, a local-only preference with no backend round trip, next to the existing privacy toggles.',
'Space Grotesk (Google Fonts, external CDN link in index.html) replaced by the preset\'s own DM Sans Variable / Outfit Variable, both self-hosted via @fontsource-variable - no external font request at all now, consistent with how the rest of the app avoids third-party runtime dependencies.',
'First full visual redesign (2026-08-23), sourced from a Stitch design export: cobalt/periwinkle-on-deep-ink Material-3-style token system (primary #b8c3ff / primary-container #2e5bff on #131313), Space Grotesk, sharp 4px-radius geometry - deliberately not the export\'s mint-green "Stax" variant, which read too close to an existing music app\'s brand color. Superseded by the shadcn swap above, but the token *names* and page structure it established are still exactly what every component uses today.',
'Tailwind v4 @theme tokens (bg-background, bg-surface-container*, text-on-surface*, bg-primary, etc.) replace the old ad-hoc neutral-900/emerald-500 classes app-wide, including UI primitives (Button, Input, EmptyState, Skeleton, ProgressBar)',
'Desktop: 256px fixed sidebar with the full nav list. Mobile: 5-tab bottom bar (Library, Discover, Social, Soundmarks, Remix) + a "More" sheet for the rest - the export\'s own floating-pill nav only assumed ~4 destinations, not enough for this app\'s real feature count',
'Every page rebuilt from its matching Stitch screen where one existed (Library, Discovery, Remix, Rooms, Channels, Upload, Business/Admin panels, Now Playing); Login, Playlists, and Telegram linking - which had no Stitch mockup - were designed from scratch to match the same system',
......@@ -276,11 +279,6 @@ const FRONTEND_TODO: WorkItem[] = [
status: 'needs-design',
note: "Noted 2026-10-06, not started - there's currently no first-run walkthrough at all; a brand-new account lands straight on Home/Library with no explanation of what Stax does or how to get music into it (Upload vs. Telegram linking vs. Discovery).",
},
{
item: 'Full visual redesign',
status: 'needs-design',
note: "Noted 2026-10-06, not started - current design system (cobalt/Space Grotesk, from the 2026-08-23 pass) isn't landing well. Discussed shadcn/ui as a reference point: worth borrowing its component anatomy/states/spacing rhythm and accessibility patterns (built on Radix primitives), but not its default visual skin (neutral grays, rounded-md) wholesale, since that would undo the deliberate cobalt/sharp-radius identity choice made over the generic/templated look.",
},
{
item: 'Investigate perceived slow-to-start playback',
status: 'needs-design',
......
......@@ -5,17 +5,20 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Settings } from './Settings'
import { AuthProvider } from '../context/AuthContext'
import { PlayerProvider } from '../context/PlayerContext'
import { ThemeProvider } from '../context/ThemeContext'
import { ApiError } from '../api/client'
import * as authApi from '../api/auth'
function renderSettings() {
return render(
<MemoryRouter>
<AuthProvider>
<PlayerProvider>
<Settings />
</PlayerProvider>
</AuthProvider>
<ThemeProvider>
<AuthProvider>
<PlayerProvider>
<Settings />
</PlayerProvider>
</AuthProvider>
</ThemeProvider>
</MemoryRouter>,
)
}
......@@ -35,6 +38,22 @@ describe('Settings', () => {
afterEach(() => {
vi.restoreAllMocks()
localStorage.removeItem('stax_theme')
})
it('defaults to dark and lets you switch appearance', async () => {
renderSettings()
const darkButton = await screen.findByRole('button', { name: 'Dark' })
expect(darkButton).toHaveAttribute('aria-pressed', 'true')
expect(screen.getByRole('button', { name: 'Light' })).toHaveAttribute('aria-pressed', 'false')
await userEvent.click(screen.getByRole('button', { name: 'Light' }))
expect(screen.getByRole('button', { name: 'Light' })).toHaveAttribute('aria-pressed', 'true')
expect(darkButton).toHaveAttribute('aria-pressed', 'false')
expect(localStorage.getItem('stax_theme')).toBe('light')
expect(document.documentElement.classList.contains('dark')).toBe(false)
})
it('renders both toggles off by default', async () => {
......
import { useEffect, useState } from 'react'
import { MapPin, MessageCircle, type LucideIcon } from 'lucide-react'
import { MapPin, MessageCircle, Monitor, Moon, Sun, type LucideIcon } from 'lucide-react'
import { Layout } from '../components/Layout'
import { ApiError } from '../api/client'
import { getMe, updatePrivacy, type PrivacySettings } from '../api/auth'
import { useTheme, type ThemePreference } from '../context/ThemeContext'
const THEME_OPTIONS: { value: ThemePreference; label: string; icon: LucideIcon }[] = [
{ value: 'light', label: 'Light', icon: Sun },
{ value: 'dark', label: 'Dark', icon: Moon },
{ value: 'system', label: 'System', icon: Monitor },
]
/** Local-only preference (see ThemeContext) - no backend round trip, unlike the privacy
* toggles below, so there's no saving/error state to manage here at all. */
function AppearanceRow() {
const { theme, setTheme } = useTheme()
return (
<div className="rounded-xl border border-outline-variant bg-surface-container p-4">
<p className="mb-3 text-sm font-medium text-on-surface">Appearance</p>
<div className="flex gap-2">
{THEME_OPTIONS.map((option) => {
const active = theme === option.value
return (
<button
key={option.value}
onClick={() => setTheme(option.value)}
aria-pressed={active}
className={`flex flex-1 items-center justify-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-medium transition-colors duration-150 ${
active
? 'bg-primary text-on-primary'
: 'border border-outline-variant bg-transparent text-on-surface-variant hover:border-primary hover:text-on-surface'
}`}
>
<option.icon size={14} strokeWidth={2} />
{option.label}
</button>
)
})}
</div>
</div>
)
}
function ToggleRow({
icon: Icon,
......@@ -84,6 +122,10 @@ export function Settings() {
{error && <p className="mb-4 text-sm text-error">{error}</p>}
<div className="mb-3">
<AppearanceRow />
</div>
{privacy && (
<div className="space-y-3">
<ToggleRow
......
......@@ -8,6 +8,12 @@
"allowArbitraryExtensions": true,
"skipLibCheck": true,
/* Path aliases - no baseUrl: deprecated under moduleResolution "bundler" (TS 6+), which
resolves `paths` relative to this file's own directory without it. */
"paths": {
"@/*": ["./src/*"]
},
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
......
......@@ -22,6 +22,11 @@ export default defineConfig(({ mode }) => {
const backendProxyTarget = env.BACKEND_PROXY_TARGET || 'http://127.0.0.1:8000'
return {
resolve: {
alias: {
'@': `${import.meta.dirname}/src`,
},
},
// The Geolocation API (and other browser APIs) refuse to run at all on a plain http://
// origin that isn't localhost - "secure context" is a hard browser requirement, not a
// permission you can grant around. basicSsl generates a self-signed cert automatically so
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment