feat: use different resource for listing songs in albums

This commit is contained in:
Deluan 2020-02-14 09:02:32 -05:00
parent b2d022b823
commit 7f94660183
5 changed files with 24 additions and 11 deletions

View File

@ -43,6 +43,7 @@ const App = () => {
<Resource name="artist" {...artist} options={{ subMenu: 'library' }} />,
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
<Resource name="song" {...song} options={{ subMenu: 'library' }} />,
<Resource name="albumSong" />,
permissions === 'admin' ? <Resource name="user" {...user} /> : null,
<Player />
]}

View File

@ -10,8 +10,8 @@ import {
import AlbumDetails from './AlbumDetails'
import { DurationField, Title } from '../common'
import { useStyles } from './styles'
import { SongBulkActions } from '../song/SongBulkActions'
import { AlbumActions } from './AlbumActions'
import { AlbumSongBulkActions } from './AlbumSongBulkActions'
import { useMediaQuery } from '@material-ui/core'
import { setTrack } from '../player'
import { useDispatch } from 'react-redux'
@ -46,13 +46,12 @@ const AlbumShow = (props) => {
title={<Title subTitle={record.name} />}
actions={<AlbumActions />}
filter={{ album_id: props.id }}
resource={'song'}
resource={'albumSong'}
exporter={false}
basePath={'/song'}
perPage={1000}
pagination={null}
sort={{ field: 'discNumber asc, trackNumber asc', order: 'ASC' }}
bulkActionButtons={<SongBulkActions />}
bulkActionButtons={<AlbumSongBulkActions />}
>
<Datagrid
rowClick={(id, basePath, record) => dispatch(setTrack(record))}

View File

@ -0,0 +1,16 @@
import React, { Fragment, useEffect } from 'react'
import { useUnselectAll } from 'react-admin'
import AddToQueueButton from '../song/AddToQueueButton'
export const AlbumSongBulkActions = (props) => {
const unselectAll = useUnselectAll()
useEffect(() => {
unselectAll('albumSong')
// eslint-disable-next-line
}, [])
return (
<Fragment>
<AddToQueueButton {...props} />
</Fragment>
)
}

View File

@ -1,7 +1,10 @@
import { fetchUtils } from 'react-admin'
import jsonServerProvider from 'ra-data-json-server'
const baseUrl = '/app/api'
const httpClient = (url, options = {}) => {
url = url.replace(baseUrl + '/albumSong', baseUrl + '/song')
if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' })
}
@ -19,6 +22,6 @@ const httpClient = (url, options = {}) => {
})
}
const dataProvider = jsonServerProvider('/app/api', httpClient)
const dataProvider = jsonServerProvider(baseUrl, httpClient)
export default dataProvider

View File

@ -1,13 +1,7 @@
import React, { Fragment, useEffect } from 'react'
import { useUnselectAll } from 'react-admin'
import AddToQueueButton from './AddToQueueButton'
export const SongBulkActions = (props) => {
const unselectAll = useUnselectAll()
useEffect(() => {
console.log('UNSELECT!')
unselectAll('song')
}, [])
return (
<Fragment>
<AddToQueueButton {...props} />