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