2021-05-26 05:35:13 -08:00
|
|
|
import React from 'react'
|
|
|
|
|
import { useSelector } from 'react-redux'
|
2020-07-29 10:12:51 -08:00
|
|
|
import { Redirect, useLocation } from 'react-router-dom'
|
2020-01-22 08:32:31 -09:00
|
|
|
import {
|
2020-03-28 12:25:55 -08:00
|
|
|
AutocompleteInput,
|
2020-01-22 08:32:31 -09:00
|
|
|
Filter,
|
2020-03-25 14:51:13 -08:00
|
|
|
NullableBooleanInput,
|
2020-03-28 12:25:55 -08:00
|
|
|
NumberInput,
|
2021-05-24 07:09:06 -08:00
|
|
|
Pagination,
|
2020-03-25 14:51:13 -08:00
|
|
|
ReferenceInput,
|
2020-03-28 12:25:55 -08:00
|
|
|
SearchInput,
|
2020-04-13 15:51:03 -08:00
|
|
|
useTranslate,
|
2020-01-22 08:32:31 -09:00
|
|
|
} from 'react-admin'
|
2021-03-26 19:56:19 -08:00
|
|
|
import FavoriteIcon from '@material-ui/icons/Favorite'
|
2020-03-28 12:25:55 -08:00
|
|
|
import { withWidth } from '@material-ui/core'
|
2021-05-26 05:35:13 -08:00
|
|
|
import {
|
|
|
|
|
List,
|
|
|
|
|
QuickFilter,
|
|
|
|
|
Title,
|
|
|
|
|
useAlbumsPerPage,
|
2021-06-09 17:02:20 -08:00
|
|
|
useResourceRefresh,
|
2021-05-26 05:35:13 -08:00
|
|
|
useSetToggleableFields,
|
|
|
|
|
} from '../common'
|
2020-03-28 12:25:55 -08:00
|
|
|
import AlbumListActions from './AlbumListActions'
|
2021-05-24 08:58:15 -08:00
|
|
|
import AlbumTableView from './AlbumTableView'
|
2020-03-28 12:25:55 -08:00
|
|
|
import AlbumGridView from './AlbumGridView'
|
2021-02-03 15:08:03 -09:00
|
|
|
import { AddToPlaylistDialog } from '../dialogs'
|
2020-07-29 10:41:18 -08:00
|
|
|
import albumLists, { defaultAlbumList } from './albumLists'
|
2021-03-28 16:35:49 -08:00
|
|
|
import config from '../config'
|
2021-09-20 16:30:43 -08:00
|
|
|
import AlbumInfo from './AlbumInfo'
|
2022-12-18 08:12:37 -09:00
|
|
|
import DownloadMenuDialog from '../dialogs/DownloadMenuDialog'
|
2021-09-20 16:30:43 -08:00
|
|
|
import ExpandInfoDialog from '../dialogs/ExpandInfoDialog'
|
2020-01-22 08:32:31 -09:00
|
|
|
|
2020-04-13 15:51:03 -08:00
|
|
|
const AlbumFilter = (props) => {
|
|
|
|
|
const translate = useTranslate()
|
|
|
|
|
return (
|
2020-08-17 07:19:39 -08:00
|
|
|
<Filter {...props} variant={'outlined'}>
|
2022-11-21 09:44:16 -09:00
|
|
|
<SearchInput id="search" source="name" alwaysOn />
|
2020-04-13 15:51:03 -08:00
|
|
|
<ReferenceInput
|
|
|
|
|
label={translate('resources.album.fields.artist')}
|
|
|
|
|
source="artist_id"
|
|
|
|
|
reference="artist"
|
|
|
|
|
sort={{ field: 'name', order: 'ASC' }}
|
|
|
|
|
filterToQuery={(searchText) => ({ name: [searchText] })}
|
|
|
|
|
>
|
|
|
|
|
<AutocompleteInput emptyText="-- None --" />
|
|
|
|
|
</ReferenceInput>
|
2021-07-16 15:41:49 -08:00
|
|
|
<ReferenceInput
|
|
|
|
|
label={translate('resources.album.fields.genre')}
|
|
|
|
|
source="genre_id"
|
|
|
|
|
reference="genre"
|
2021-07-24 12:00:27 -08:00
|
|
|
perPage={0}
|
2021-07-16 15:41:49 -08:00
|
|
|
sort={{ field: 'name', order: 'ASC' }}
|
|
|
|
|
filterToQuery={(searchText) => ({ name: [searchText] })}
|
|
|
|
|
>
|
|
|
|
|
<AutocompleteInput emptyText="-- None --" />
|
|
|
|
|
</ReferenceInput>
|
2020-04-13 15:51:03 -08:00
|
|
|
<NullableBooleanInput source="compilation" />
|
|
|
|
|
<NumberInput source="year" />
|
2021-03-28 16:35:49 -08:00
|
|
|
{config.enableFavourites && (
|
|
|
|
|
<QuickFilter
|
|
|
|
|
source="starred"
|
|
|
|
|
label={<FavoriteIcon fontSize={'small'} />}
|
|
|
|
|
defaultValue={true}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-04-13 15:51:03 -08:00
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-01-22 08:32:31 -09:00
|
|
|
|
2020-07-29 10:24:24 -08:00
|
|
|
const AlbumListTitle = ({ albumListType }) => {
|
|
|
|
|
const translate = useTranslate()
|
|
|
|
|
let title = translate('resources.album.name', { smart_count: 2 })
|
|
|
|
|
if (albumListType) {
|
|
|
|
|
let listTitle = translate(`resources.album.lists.${albumListType}`, {
|
|
|
|
|
smart_count: 2,
|
|
|
|
|
})
|
|
|
|
|
title = `${title} - ${listTitle}`
|
|
|
|
|
}
|
|
|
|
|
return <Title subTitle={title} args={{ smart_count: 2 }} />
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 08:36:26 -09:00
|
|
|
const AlbumList = (props) => {
|
2021-02-02 13:49:11 -09:00
|
|
|
const { width } = props
|
2020-03-28 12:25:55 -08:00
|
|
|
const albumView = useSelector((state) => state.albumView)
|
2020-06-09 16:29:12 -08:00
|
|
|
const [perPage, perPageOptions] = useAlbumsPerPage(width)
|
|
|
|
|
const location = useLocation()
|
2021-06-09 17:02:20 -08:00
|
|
|
useResourceRefresh('album')
|
2020-06-09 16:29:12 -08:00
|
|
|
|
2020-07-29 10:24:24 -08:00
|
|
|
const albumListType = location.pathname
|
|
|
|
|
.replace(/^\/album/, '')
|
|
|
|
|
.replace(/^\//, '')
|
|
|
|
|
|
2021-05-24 07:09:06 -08:00
|
|
|
// Workaround to force album columns to appear the first time.
|
|
|
|
|
// See https://github.com/navidrome/navidrome/pull/923#issuecomment-833004842
|
|
|
|
|
// TODO: Find a better solution
|
2022-12-22 18:44:07 -09:00
|
|
|
useSetToggleableFields(
|
|
|
|
|
'album',
|
|
|
|
|
[
|
|
|
|
|
'artist',
|
|
|
|
|
'songCount',
|
|
|
|
|
'playCount',
|
|
|
|
|
'year',
|
|
|
|
|
'duration',
|
|
|
|
|
'rating',
|
|
|
|
|
'createdAt',
|
|
|
|
|
],
|
|
|
|
|
['createdAt']
|
|
|
|
|
)
|
2021-05-24 07:09:06 -08:00
|
|
|
|
2020-07-29 10:12:51 -08:00
|
|
|
// If it does not have filter/sort params (usually coming from Menu),
|
|
|
|
|
// reload with correct filter/sort params
|
|
|
|
|
if (!location.search) {
|
2020-07-29 10:41:18 -08:00
|
|
|
const type =
|
|
|
|
|
albumListType || localStorage.getItem('defaultView') || defaultAlbumList
|
2020-07-29 10:12:51 -08:00
|
|
|
const listParams = albumLists[type]
|
|
|
|
|
if (listParams) {
|
|
|
|
|
return <Redirect to={`/album/${type}?${listParams.params}`} />
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 08:36:26 -09:00
|
|
|
return (
|
2020-05-25 14:34:31 -08:00
|
|
|
<>
|
|
|
|
|
<List
|
|
|
|
|
{...props}
|
|
|
|
|
exporter={false}
|
|
|
|
|
bulkActionButtons={false}
|
|
|
|
|
actions={<AlbumListActions />}
|
|
|
|
|
filters={<AlbumFilter />}
|
2020-06-09 16:29:12 -08:00
|
|
|
perPage={perPage}
|
|
|
|
|
pagination={<Pagination rowsPerPageOptions={perPageOptions} />}
|
2020-07-29 10:24:24 -08:00
|
|
|
title={<AlbumListTitle albumListType={albumListType} />}
|
2020-05-25 14:34:31 -08:00
|
|
|
>
|
2020-11-08 09:15:46 -09:00
|
|
|
{albumView.grid ? (
|
2021-05-05 11:44:48 -08:00
|
|
|
<AlbumGridView albumListType={albumListType} {...props} />
|
2020-11-08 09:15:46 -09:00
|
|
|
) : (
|
2021-05-24 08:58:15 -08:00
|
|
|
<AlbumTableView {...props} />
|
2020-05-25 14:34:31 -08:00
|
|
|
)}
|
|
|
|
|
</List>
|
2020-05-28 04:16:31 -08:00
|
|
|
<AddToPlaylistDialog />
|
2022-12-18 08:12:37 -09:00
|
|
|
<DownloadMenuDialog />
|
2021-09-20 16:30:43 -08:00
|
|
|
<ExpandInfoDialog content={<AlbumInfo />} />
|
2020-05-25 14:34:31 -08:00
|
|
|
</>
|
2020-02-07 08:36:26 -09:00
|
|
|
)
|
|
|
|
|
}
|
2020-03-28 12:25:55 -08:00
|
|
|
|
|
|
|
|
export default withWidth()(AlbumList)
|