Skip to content

Commit

Permalink
Add option to select default album view
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 29, 2020
1 parent 8daac43 commit 3092f83
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion resources/i18n/pt.json
Expand Up @@ -263,7 +263,8 @@
"name": "Pessoal",
"options": {
"theme": "Tema",
"language": "L铆ngua"
"language": "L铆ngua",
"defaultView": "Tela inicial"
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions ui/src/album/AlbumList.js
Expand Up @@ -19,7 +19,7 @@ import AlbumListView from './AlbumListView'
import AlbumGridView from './AlbumGridView'
import { ALBUM_MODE_LIST } from './albumState'
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
import albumLists from './albumLists'
import albumLists, { defaultAlbumList } from './albumLists'

const AlbumFilter = (props) => {
const translate = useTranslate()
Expand Down Expand Up @@ -73,7 +73,8 @@ const AlbumList = (props) => {
// If it does not have filter/sort params (usually coming from Menu),
// reload with correct filter/sort params
if (!location.search) {
const type = albumListType || 'all'
const type =
albumListType || localStorage.getItem('defaultView') || defaultAlbumList
const listParams = albumLists[type]
if (listParams) {
return <Redirect to={`/album/${type}?${listParams.params}`} />
Expand Down
2 changes: 2 additions & 0 deletions ui/src/album/albumLists.js
Expand Up @@ -23,3 +23,5 @@ export default {
params: 'sort=play_count&order=DESC&filter={"recently_played":true}',
},
}

export const defaultAlbumList = 'recentlyAdded'
3 changes: 2 additions & 1 deletion ui/src/i18n/en.json
Expand Up @@ -264,7 +264,8 @@
"name": "Personal",
"options": {
"theme": "Theme",
"language": "Language"
"language": "Language",
"defaultView": "Default View"
}
}
},
Expand Down
25 changes: 25 additions & 0 deletions ui/src/personal/Personal.js
Expand Up @@ -15,6 +15,7 @@ import { changeTheme } from './actions'
import themes from '../themes'
import { docsUrl } from '../utils/docsUrl'
import { useGetLanguageChoices } from '../i18n'
import albumLists, { defaultAlbumList } from '../album/albumLists'

const useStyles = makeStyles({
root: { marginTop: '1em' },
Expand Down Expand Up @@ -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 translate = useTranslate()
const classes = useStyles()
Expand All @@ -105,6 +129,7 @@ const Personal = () => {
<SimpleForm toolbar={null}>
<SelectTheme />
<SelectLanguage />
<SelectDefaultView />
</SimpleForm>
</Card>
)
Expand Down

0 comments on commit 3092f83

Please sign in to comment.