feat: load themes dynamically
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useSelector, useDispatch } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import Card from '@material-ui/core/Card'
|
import { Card, CardContent, MenuItem, Select } from '@material-ui/core'
|
||||||
import CardContent from '@material-ui/core/CardContent'
|
import { Title, useTranslate } from 'react-admin'
|
||||||
import Button from '@material-ui/core/Button'
|
|
||||||
import { useTranslate, Title } from 'react-admin'
|
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import { changeTheme } from './actions'
|
import { changeTheme } from './actions'
|
||||||
|
import themes from '../themes'
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
label: { width: '10em', display: 'inline-block' },
|
label: { width: '10em', display: 'inline-block' },
|
||||||
@@ -17,27 +16,24 @@ const Configuration = () => {
|
|||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const theme = useSelector((state) => state.theme)
|
const theme = useSelector((state) => state.theme)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const themeNames = Object.keys(themes).sort()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<Title title={translate('menu.configuration')} />
|
<Title title={translate('menu.configuration')} />
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className={classes.label}>{translate('menu.theme.name')}</div>
|
<div className={classes.label}>{translate('menu.theme')}</div>
|
||||||
<Button
|
<Select
|
||||||
variant="contained"
|
value={theme}
|
||||||
className={classes.button}
|
variant="filled"
|
||||||
color={theme === 'light' ? 'primary' : 'default'}
|
onChange={(event) => {
|
||||||
onClick={() => dispatch(changeTheme('light'))}
|
dispatch(changeTheme(event.target.value))
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{translate('theme.light')}
|
{themeNames.map((t) => (
|
||||||
</Button>
|
<MenuItem value={t}>{themes[t].name}</MenuItem>
|
||||||
<Button
|
))}
|
||||||
variant="contained"
|
</Select>
|
||||||
className={classes.button}
|
|
||||||
color={theme === 'dark' ? 'primary' : 'default'}
|
|
||||||
onClick={() => dispatch(changeTheme('dark'))}
|
|
||||||
>
|
|
||||||
{translate('theme.dark')}
|
|
||||||
</Button>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CHANGE_THEME } from './actions'
|
import { CHANGE_THEME } from './actions'
|
||||||
|
|
||||||
export default (previousState = 'dark', { type, payload }) => {
|
export default (previousState = 'DarkTheme', { type, payload }) => {
|
||||||
if (type === CHANGE_THEME) {
|
if (type === CHANGE_THEME) {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -47,13 +47,7 @@ export default deepmerge(englishMessages, {
|
|||||||
settings: 'Settings',
|
settings: 'Settings',
|
||||||
configuration: 'Configuration',
|
configuration: 'Configuration',
|
||||||
version: 'Version %{version}',
|
version: 'Version %{version}',
|
||||||
theme: {
|
theme: 'Theme'
|
||||||
name: 'Theme'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
theme: {
|
|
||||||
dark: 'Dark',
|
|
||||||
light: 'Light'
|
|
||||||
},
|
},
|
||||||
player: {
|
player: {
|
||||||
panelTitle: 'Play Queue',
|
panelTitle: 'Play Queue',
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Layout } from 'react-admin'
|
|||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import Menu from './Menu'
|
import Menu from './Menu'
|
||||||
import AppBar from './AppBar'
|
import AppBar from './AppBar'
|
||||||
import { DarkTheme, LightTheme } from '../themes'
|
import themes from '../themes'
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: { paddingBottom: '80px' }
|
root: { paddingBottom: '80px' }
|
||||||
@@ -12,12 +12,9 @@ const useStyles = makeStyles({
|
|||||||
|
|
||||||
export default (props) => {
|
export default (props) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const theme = useSelector((state) =>
|
const theme = useSelector((state) => themes[state.theme] || themes.DarkTheme)
|
||||||
state.theme === 'dark' ? DarkTheme : LightTheme
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<Layout
|
<Layout
|
||||||
{...props}
|
{...props}
|
||||||
className={classes.root}
|
className={classes.root}
|
||||||
@@ -25,6 +22,5 @@ export default (props) => {
|
|||||||
appBar={AppBar}
|
appBar={AppBar}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
/>
|
/>
|
||||||
</>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import LockIcon from '@material-ui/icons/Lock'
|
|||||||
|
|
||||||
import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
|
import { Notification, useLogin, useNotify, useTranslate } from 'react-admin'
|
||||||
|
|
||||||
import { LightTheme } from '../themes'
|
import LightTheme from '../themes/light'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
main: {
|
main: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import blue from '@material-ui/core/colors/blue'
|
import blue from '@material-ui/core/colors/blue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
name: 'Dark (default)',
|
||||||
palette: {
|
palette: {
|
||||||
primary: {
|
primary: {
|
||||||
main: '#90caf9'
|
main: '#90caf9'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import LightTheme from './light'
|
import LightTheme from './light'
|
||||||
import DarkTheme from './dark'
|
import DarkTheme from './dark'
|
||||||
|
|
||||||
export { LightTheme, DarkTheme }
|
export default { LightTheme, DarkTheme }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
|
name: 'Light',
|
||||||
palette: {
|
palette: {
|
||||||
secondary: {
|
secondary: {
|
||||||
light: '#5f5fc4',
|
light: '#5f5fc4',
|
||||||
|
|||||||
Reference in New Issue
Block a user