navidrome/ui/src/themes/useCurrentTheme.js
2021-04-18 13:51:00 -04:00

21 lines
651 B
JavaScript

import { useSelector } from 'react-redux'
import useMediaQuery from '@material-ui/core/useMediaQuery'
import themes from './index'
import { AUTO_THEME_ID } from '../consts'
import config from '../config'
export default () => {
const prefersLightMode = useMediaQuery('(prefers-color-scheme: light)')
return useSelector((state) => {
if (state.theme === AUTO_THEME_ID) {
return prefersLightMode ? themes.LightTheme : themes.DarkTheme
}
const themeName =
state.theme ||
Object.keys(themes).find(
(t) => themes[t].themeName === config.defaultTheme
) ||
'DarkTheme'
return themes[themeName]
})
}