2020-01-22 08:32:31 -09:00
|
|
|
import React from 'react'
|
2020-03-28 12:25:55 -08:00
|
|
|
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,
|
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
|
|
|
Pagination,
|
|
|
|
|
useTranslate,
|
2020-06-09 16:29:12 -08:00
|
|
|
useListParams,
|
2020-01-22 08:32:31 -09:00
|
|
|
} from 'react-admin'
|
2020-06-09 16:29:12 -08:00
|
|
|
import { List, useAlbumsPerPage } from '../common'
|
2020-03-28 12:25:55 -08:00
|
|
|
import { withWidth } from '@material-ui/core'
|
|
|
|
|
import AlbumListActions from './AlbumListActions'
|
|
|
|
|
import AlbumListView from './AlbumListView'
|
|
|
|
|
import AlbumGridView from './AlbumGridView'
|
2020-03-28 19:25:49 -08:00
|
|
|
import { ALBUM_MODE_LIST } from './albumState'
|
2020-05-25 14:34:31 -08:00
|
|
|
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
2020-07-29 10:12:51 -08:00
|
|
|
import albumLists from './albumLists'
|
2020-01-22 08:32:31 -09:00
|
|
|
|
2020-04-13 15:51:03 -08:00
|
|
|
const AlbumFilter = (props) => {
|
|
|
|
|
const translate = useTranslate()
|
|
|
|
|
return (
|
|
|
|
|
<Filter {...props}>
|
|
|
|
|
<SearchInput source="name" alwaysOn />
|
|
|
|
|
<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>
|
|
|
|
|
<NullableBooleanInput source="compilation" />
|
|
|
|
|
<NumberInput source="year" />
|
|
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-01-22 08:32:31 -09:00
|
|
|
|
2020-02-07 08:36:26 -09:00
|
|
|
const AlbumList = (props) => {
|
2020-06-09 16:29:12 -08:00
|
|
|
const { width, resource } = 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()
|
|
|
|
|
|
|
|
|
|
const [query] = useListParams({
|
|
|
|
|
resource,
|
|
|
|
|
location,
|
|
|
|
|
perPage,
|
|
|
|
|
})
|
|
|
|
|
const isArtistView = !!(query.filter && query.filter.artist_id)
|
|
|
|
|
|
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) {
|
|
|
|
|
let type =
|
|
|
|
|
location.pathname.replace(/^\/album/, '').replace(/^\//, '') || 'all'
|
|
|
|
|
|
|
|
|
|
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-05-25 14:34:31 -08:00
|
|
|
>
|
|
|
|
|
{albumView.mode === ALBUM_MODE_LIST ? (
|
|
|
|
|
<AlbumListView {...props} />
|
|
|
|
|
) : (
|
2020-06-09 16:29:12 -08:00
|
|
|
<AlbumGridView isArtistView={isArtistView} {...props} />
|
2020-05-25 14:34:31 -08:00
|
|
|
)}
|
|
|
|
|
</List>
|
2020-05-28 04:16:31 -08:00
|
|
|
<AddToPlaylistDialog />
|
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)
|