Skip to content

Commit

Permalink
feat: use different resource for listing songs in albums
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Feb 14, 2020
1 parent b2d022b commit 7f94660
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
]}
Expand Down
7 changes: 3 additions & 4 deletions ui/src/album/AlbumShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))}
Expand Down
16 changes: 16 additions & 0 deletions ui/src/album/AlbumSongBulkActions.js
Original file line number Diff line number Diff line change
@@ -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>
)
}
5 changes: 4 additions & 1 deletion ui/src/dataProvider.js
Original file line number Diff line number Diff line change
@@ -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' })
}
Expand All @@ -19,6 +22,6 @@ const httpClient = (url, options = {}) => {
})
}

const dataProvider = jsonServerProvider('/app/api', httpClient)
const dataProvider = jsonServerProvider(baseUrl, httpClient)

export default dataProvider
6 changes: 0 additions & 6 deletions ui/src/song/SongBulkActions.js
Original file line number Diff line number Diff line change
@@ -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} />
Expand Down

0 comments on commit 7f94660

Please sign in to comment.