Add option to select default album view

This commit is contained in:
Deluan 2020-07-29 14:41:18 -04:00 committed by Deluan Quintão
parent 8daac43e99
commit 3092f83a00
5 changed files with 34 additions and 4 deletions

View File

@ -263,7 +263,8 @@
"name": "Pessoal", "name": "Pessoal",
"options": { "options": {
"theme": "Tema", "theme": "Tema",
"language": "Língua" "language": "Língua",
"defaultView": "Tela inicial"
} }
} }
}, },

View File

@ -19,7 +19,7 @@ import AlbumListView from './AlbumListView'
import AlbumGridView from './AlbumGridView' import AlbumGridView from './AlbumGridView'
import { ALBUM_MODE_LIST } from './albumState' import { ALBUM_MODE_LIST } from './albumState'
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog' import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
import albumLists from './albumLists' import albumLists, { defaultAlbumList } from './albumLists'
const AlbumFilter = (props) => { const AlbumFilter = (props) => {
const translate = useTranslate() const translate = useTranslate()
@ -73,7 +73,8 @@ const AlbumList = (props) => {
// If it does not have filter/sort params (usually coming from Menu), // If it does not have filter/sort params (usually coming from Menu),
// reload with correct filter/sort params // reload with correct filter/sort params
if (!location.search) { if (!location.search) {
const type = albumListType || 'all' const type =
albumListType || localStorage.getItem('defaultView') || defaultAlbumList
const listParams = albumLists[type] const listParams = albumLists[type]
if (listParams) { if (listParams) {
return <Redirect to={`/album/${type}?${listParams.params}`} /> return <Redirect to={`/album/${type}?${listParams.params}`} />

View File

@ -23,3 +23,5 @@ export default {
params: 'sort=play_count&order=DESC&filter={"recently_played":true}', params: 'sort=play_count&order=DESC&filter={"recently_played":true}',
}, },
} }
export const defaultAlbumList = 'recentlyAdded'

View File

@ -264,7 +264,8 @@
"name": "Personal", "name": "Personal",
"options": { "options": {
"theme": "Theme", "theme": "Theme",
"language": "Language" "language": "Language",
"defaultView": "Default View"
} }
} }
}, },

View File

@ -15,6 +15,7 @@ import { changeTheme } from './actions'
import themes from '../themes' import themes from '../themes'
import { docsUrl } from '../utils/docsUrl' import { docsUrl } from '../utils/docsUrl'
import { useGetLanguageChoices } from '../i18n' import { useGetLanguageChoices } from '../i18n'
import albumLists, { defaultAlbumList } from '../album/albumLists'
const useStyles = makeStyles({ const useStyles = makeStyles({
root: { marginTop: '1em' }, root: { marginTop: '1em' },
@ -95,6 +96,29 @@ const SelectTheme = (props) => {
) )
} }
const SelectDefaultView = (props) => {
const translate = useTranslate()
const current = localStorage.getItem('defaultView') || defaultAlbumList
const choices = Object.keys(albumLists).map((type) => ({
id: type,
name: translate(`resources.album.lists.${type}`),
}))
return (
<SelectInput
{...props}
source="defaultView"
label={translate('menu.personal.options.defaultView')}
defaultValue={current}
choices={choices}
translateChoice={false}
onChange={(event) => {
localStorage.setItem('defaultView', event.target.value)
}}
/>
)
}
const Personal = () => { const Personal = () => {
const translate = useTranslate() const translate = useTranslate()
const classes = useStyles() const classes = useStyles()
@ -105,6 +129,7 @@ const Personal = () => {
<SimpleForm toolbar={null}> <SimpleForm toolbar={null}>
<SelectTheme /> <SelectTheme />
<SelectLanguage /> <SelectLanguage />
<SelectDefaultView />
</SimpleForm> </SimpleForm>
</Card> </Card>
) )