Add Language Selector to Personal settings
This commit is contained in:
+3
-1
@@ -19,6 +19,7 @@ export default deepmerge(englishMessages, {
|
|||||||
album: {
|
album: {
|
||||||
fields: {
|
fields: {
|
||||||
albumArtist: 'Album Artist',
|
albumArtist: 'Album Artist',
|
||||||
|
artist: 'Artist',
|
||||||
duration: 'Time',
|
duration: 'Time',
|
||||||
songCount: 'Songs',
|
songCount: 'Songs',
|
||||||
playCount: 'Plays'
|
playCount: 'Plays'
|
||||||
@@ -51,7 +52,8 @@ export default deepmerge(englishMessages, {
|
|||||||
personal: {
|
personal: {
|
||||||
name: 'Personal',
|
name: 'Personal',
|
||||||
options: {
|
options: {
|
||||||
theme: 'Theme'
|
theme: 'Theme',
|
||||||
|
language: 'Language'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-1
@@ -88,7 +88,8 @@ export default deepmerge.all([
|
|||||||
personal: {
|
personal: {
|
||||||
name: 'Pessoal',
|
name: 'Pessoal',
|
||||||
options: {
|
options: {
|
||||||
theme: 'Tema'
|
theme: 'Tema',
|
||||||
|
language: 'Língua'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+50
-13
@@ -1,37 +1,74 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { Card } from '@material-ui/core'
|
import { Card } from '@material-ui/core'
|
||||||
import { Title, SimpleForm, SelectInput, useTranslate } from 'react-admin'
|
import {
|
||||||
|
Title,
|
||||||
|
SimpleForm,
|
||||||
|
SelectInput,
|
||||||
|
useTranslate,
|
||||||
|
useSetLocale,
|
||||||
|
useLocale
|
||||||
|
} 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'
|
import themes from '../themes'
|
||||||
|
import i18n from '../i18n'
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: { marginTop: '1em' }
|
root: { marginTop: '1em' }
|
||||||
})
|
})
|
||||||
|
|
||||||
const Personal = () => {
|
const SelectLanguage = (props) => {
|
||||||
|
const translate = useTranslate()
|
||||||
|
const locale = useLocale()
|
||||||
|
const setLocale = useSetLocale()
|
||||||
|
const langChoices = Object.keys(i18n).map((key) => {
|
||||||
|
return { id: key, name: i18n[key].languageName }
|
||||||
|
})
|
||||||
|
return (
|
||||||
|
<SelectInput
|
||||||
|
{...props}
|
||||||
|
source="lamguage"
|
||||||
|
label={translate('menu.personal.options.language')}
|
||||||
|
defaultValue={locale}
|
||||||
|
choices={langChoices}
|
||||||
|
onChange={(event) => {
|
||||||
|
setLocale(event.target.value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const SelectTheme = (props) => {
|
||||||
const translate = useTranslate()
|
const translate = useTranslate()
|
||||||
const classes = useStyles()
|
|
||||||
const currentTheme = useSelector((state) => state.theme)
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const currentTheme = useSelector((state) => state.theme)
|
||||||
const themeChoices = Object.keys(themes).map((key) => {
|
const themeChoices = Object.keys(themes).map((key) => {
|
||||||
return { id: key, name: themes[key].themeName }
|
return { id: key, name: themes[key].themeName }
|
||||||
})
|
})
|
||||||
|
return (
|
||||||
|
<SelectInput
|
||||||
|
{...props}
|
||||||
|
source="theme"
|
||||||
|
label={translate('menu.personal.options.theme')}
|
||||||
|
defaultValue={currentTheme}
|
||||||
|
choices={themeChoices}
|
||||||
|
onChange={(event) => {
|
||||||
|
dispatch(changeTheme(event.target.value))
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const Personal = () => {
|
||||||
|
const translate = useTranslate()
|
||||||
|
const classes = useStyles()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={classes.root}>
|
<Card className={classes.root}>
|
||||||
<Title title={'Navidrome - ' + translate('menu.personal.name')} />
|
<Title title={'Navidrome - ' + translate('menu.personal.name')} />
|
||||||
<SimpleForm toolbar={null}>
|
<SimpleForm toolbar={null}>
|
||||||
<SelectInput
|
<SelectTheme />
|
||||||
source="theme"
|
<SelectLanguage />
|
||||||
label={translate('menu.personal.options.theme')}
|
|
||||||
defaultValue={currentTheme}
|
|
||||||
choices={themeChoices}
|
|
||||||
onChange={(event) => {
|
|
||||||
dispatch(changeTheme(event.target.value))
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</SimpleForm>
|
</SimpleForm>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user