Add Language Selector to Personal settings

This commit is contained in:
Deluan
2020-04-13 21:19:31 -04:00
committed by Deluan Quintão
parent 289ba68824
commit bf6ec67528
3 changed files with 55 additions and 15 deletions
+3 -1
View File
@@ -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
View File
@@ -88,7 +88,8 @@ export default deepmerge.all([
personal: { personal: {
name: 'Pessoal', name: 'Pessoal',
options: { options: {
theme: 'Tema' theme: 'Tema',
language: 'Língua'
} }
} }
}, },
+45 -8
View File
@@ -1,29 +1,54 @@
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 ( return (
<Card className={classes.root}>
<Title title={'Navidrome - ' + translate('menu.personal.name')} />
<SimpleForm toolbar={null}>
<SelectInput <SelectInput
{...props}
source="theme" source="theme"
label={translate('menu.personal.options.theme')} label={translate('menu.personal.options.theme')}
defaultValue={currentTheme} defaultValue={currentTheme}
@@ -32,6 +57,18 @@ const Personal = () => {
dispatch(changeTheme(event.target.value)) dispatch(changeTheme(event.target.value))
}} }}
/> />
)
}
const Personal = () => {
const translate = useTranslate()
const classes = useStyles()
return (
<Card className={classes.root}>
<Title title={'Navidrome - ' + translate('menu.personal.name')} />
<SimpleForm toolbar={null}>
<SelectTheme />
<SelectLanguage />
</SimpleForm> </SimpleForm>
</Card> </Card>
) )