mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-11 20:07:11 +02:00
* fix(ui): allow DefaultTheme "Auto" from config When DefaultTheme is set to "Auto" in the server config, the defaultTheme() function in themeReducer now returns AUTO_THEME_ID instead of falling through to the DarkTheme fallback. This allows useCurrentTheme to correctly read prefers-color-scheme and select Light or Dark theme automatically for new/incognito users. Adds themeReducer unit tests covering Auto, named-theme, and unrecognized-value fallback paths. * chore: format Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org> Co-authored-by: Deluan <deluan@navidrome.org>
25 lines
585 B
JavaScript
25 lines
585 B
JavaScript
import { CHANGE_THEME } from '../actions'
|
|
import { AUTO_THEME_ID, AUTO_THEME_CONFIG_VALUE } from '../consts'
|
|
import config from '../config'
|
|
import themes from '../themes'
|
|
|
|
const defaultTheme = () => {
|
|
if (config.defaultTheme === AUTO_THEME_CONFIG_VALUE) {
|
|
return AUTO_THEME_ID
|
|
}
|
|
return (
|
|
Object.keys(themes).find(
|
|
(t) => themes[t].themeName === config.defaultTheme,
|
|
) || 'DarkTheme'
|
|
)
|
|
}
|
|
|
|
export const themeReducer = (
|
|
previousState = defaultTheme(),
|
|
{ type, payload },
|
|
) => {
|
|
if (type === CHANGE_THEME) {
|
|
return payload
|
|
}
|
|
return previousState
|
|
}
|