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
+1
View File
@@ -43,6 +43,7 @@ const App = () => {
<Resource name="artist" {...artist} options={{ subMenu: 'library' }} />, <Resource name="artist" {...artist} options={{ subMenu: 'library' }} />,
<Resource name="album" {...album} options={{ subMenu: 'library' }} />, <Resource name="album" {...album} options={{ subMenu: 'library' }} />,
<Resource name="song" {...song} options={{ subMenu: 'library' }} />, <Resource name="song" {...song} options={{ subMenu: 'library' }} />,
<Resource name="albumSong" />,
permissions === 'admin' ? <Resource name="user" {...user} /> : null, permissions === 'admin' ? <Resource name="user" {...user} /> : null,
<Player /> <Player />
]} ]}
+3 -4
View File
@@ -10,8 +10,8 @@ import {
import AlbumDetails from './AlbumDetails' import AlbumDetails from './AlbumDetails'
import { DurationField, Title } from '../common' import { DurationField, Title } from '../common'
import { useStyles } from './styles' import { useStyles } from './styles'
import { SongBulkActions } from '../song/SongBulkActions'
import { AlbumActions } from './AlbumActions' import { AlbumActions } from './AlbumActions'
import { AlbumSongBulkActions } from './AlbumSongBulkActions'
import { useMediaQuery } from '@material-ui/core' import { useMediaQuery } from '@material-ui/core'
import { setTrack } from '../player' import { setTrack } from '../player'
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
@@ -46,13 +46,12 @@ const AlbumShow = (props) => {
title={<Title subTitle={record.name} />} title={<Title subTitle={record.name} />}
actions={<AlbumActions />} actions={<AlbumActions />}
filter={{ album_id: props.id }} filter={{ album_id: props.id }}
resource={'song'} resource={'albumSong'}
exporter={false} exporter={false}
basePath={'/song'}
perPage={1000} perPage={1000}
pagination={null} pagination={null}
sort={{ field: 'discNumber asc, trackNumber asc', order: 'ASC' }} sort={{ field: 'discNumber asc, trackNumber asc', order: 'ASC' }}
bulkActionButtons={<SongBulkActions />} bulkActionButtons={<AlbumSongBulkActions />}
> >
<Datagrid <Datagrid
rowClick={(id, basePath, record) => dispatch(setTrack(record))} rowClick={(id, basePath, record) => dispatch(setTrack(record))}
+16
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>
)
}
+4 -1
View File
@@ -1,7 +1,10 @@
import { fetchUtils } from 'react-admin' import { fetchUtils } from 'react-admin'
import jsonServerProvider from 'ra-data-json-server' import jsonServerProvider from 'ra-data-json-server'
const baseUrl = '/app/api'
const httpClient = (url, options = {}) => { const httpClient = (url, options = {}) => {
url = url.replace(baseUrl + '/albumSong', baseUrl + '/song')
if (!options.headers) { if (!options.headers) {
options.headers = new Headers({ Accept: 'application/json' }) 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 export default dataProvider
-6
View File
@@ -1,13 +1,7 @@
import React, { Fragment, useEffect } from 'react' import React, { Fragment, useEffect } from 'react'
import { useUnselectAll } from 'react-admin'
import AddToQueueButton from './AddToQueueButton' import AddToQueueButton from './AddToQueueButton'
export const SongBulkActions = (props) => { export const SongBulkActions = (props) => {
const unselectAll = useUnselectAll()
useEffect(() => {
console.log('UNSELECT!')
unselectAll('song')
}, [])
return ( return (
<Fragment> <Fragment>
<AddToQueueButton {...props} /> <AddToQueueButton {...props} />