Remove duplicated code for SongBulkActions
This commit is contained in:
@@ -3,7 +3,7 @@ import { useGetOne } from 'react-admin'
|
|||||||
import AlbumDetails from './AlbumDetails'
|
import AlbumDetails from './AlbumDetails'
|
||||||
import { Title } from '../common'
|
import { Title } from '../common'
|
||||||
import { useStyles } from './styles'
|
import { useStyles } from './styles'
|
||||||
import { AlbumSongBulkActions } from './AlbumSongBulkActions'
|
import { SongBulkActions } from '../common'
|
||||||
import AlbumActions from './AlbumActions'
|
import AlbumActions from './AlbumActions'
|
||||||
import AlbumSongs from './AlbumSongs'
|
import AlbumSongs from './AlbumSongs'
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ const AlbumShow = (props) => {
|
|||||||
perPage={0}
|
perPage={0}
|
||||||
pagination={null}
|
pagination={null}
|
||||||
sort={{ field: 'discNumber asc, trackNumber asc', order: 'ASC' }}
|
sort={{ field: 'discNumber asc, trackNumber asc', order: 'ASC' }}
|
||||||
bulkActionButtons={<AlbumSongBulkActions />}
|
bulkActionButtons={<SongBulkActions />}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
useDataProvider,
|
useDataProvider,
|
||||||
@@ -7,8 +8,6 @@ import {
|
|||||||
useNotify,
|
useNotify,
|
||||||
} from 'react-admin'
|
} from 'react-admin'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { addTracks } from '../audioplayer'
|
|
||||||
import { RiPlayListAddFill } from 'react-icons/ri'
|
|
||||||
|
|
||||||
const BatchPlayButton = ({ resource, selectedIds, action, label, icon }) => {
|
const BatchPlayButton = ({ resource, selectedIds, action, label, icon }) => {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@@ -42,10 +41,10 @@ const BatchPlayButton = ({ resource, selectedIds, action, label, icon }) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BatchPlayButton.defaultProps = {
|
BatchPlayButton.propTypes = {
|
||||||
action: addTracks,
|
action: PropTypes.func.isRequired,
|
||||||
label: 'resources.song.actions.addToQueue',
|
label: PropTypes.string.isRequired,
|
||||||
icon: <RiPlayListAddFill />,
|
icon: PropTypes.object.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BatchPlayButton
|
export default BatchPlayButton
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React, { Fragment, useEffect } from 'react'
|
import React, { Fragment, useEffect } from 'react'
|
||||||
import { useUnselectAll } from 'react-admin'
|
import { useUnselectAll } from 'react-admin'
|
||||||
import { playNext, playTracks } from '../audioplayer'
|
import { addTracks, playNext, playTracks } from '../audioplayer'
|
||||||
import { RiPlayList2Fill } from 'react-icons/ri'
|
import { RiPlayList2Fill, RiPlayListAddFill } from 'react-icons/ri'
|
||||||
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
||||||
import { BatchPlayButton } from '../common'
|
import { BatchPlayButton } from './index'
|
||||||
import AddToPlaylistButton from '../song/AddToPlaylistButton'
|
import AddToPlaylistButton from './AddToPlaylistButton'
|
||||||
|
|
||||||
export const AlbumSongBulkActions = (props) => {
|
const SongBulkActions = (props) => {
|
||||||
const unselectAll = useUnselectAll()
|
const unselectAll = useUnselectAll()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
unselectAll('albumSong')
|
unselectAll(props.resource)
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
}, [])
|
}, [])
|
||||||
return (
|
return (
|
||||||
@@ -26,8 +26,15 @@ export const AlbumSongBulkActions = (props) => {
|
|||||||
label={'resources.song.actions.playNext'}
|
label={'resources.song.actions.playNext'}
|
||||||
icon={<RiPlayList2Fill />}
|
icon={<RiPlayList2Fill />}
|
||||||
/>
|
/>
|
||||||
<BatchPlayButton {...props} />
|
<BatchPlayButton
|
||||||
|
{...props}
|
||||||
|
action={addTracks}
|
||||||
|
label={'resources.song.actions.addToQueue'}
|
||||||
|
icon={<RiPlayListAddFill />}
|
||||||
|
/>
|
||||||
<AddToPlaylistButton {...props} />
|
<AddToPlaylistButton {...props} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default SongBulkActions
|
||||||
@@ -4,6 +4,8 @@ import BitrateField from './BitrateField'
|
|||||||
import Pagination from './Pagination'
|
import Pagination from './Pagination'
|
||||||
import PlayButton from './PlayButton'
|
import PlayButton from './PlayButton'
|
||||||
import BatchPlayButton from './BatchPlayButton'
|
import BatchPlayButton from './BatchPlayButton'
|
||||||
|
import SongBulkActions from './SongBulkActions'
|
||||||
|
import AddToPlaylistButton from './AddToPlaylistButton'
|
||||||
import SimpleList from './SimpleList'
|
import SimpleList from './SimpleList'
|
||||||
import RangeField, { formatRange } from './RangeField'
|
import RangeField, { formatRange } from './RangeField'
|
||||||
import ArtistLinkField, { useGetHandleArtistClick } from './ArtistLinkField'
|
import ArtistLinkField, { useGetHandleArtistClick } from './ArtistLinkField'
|
||||||
@@ -29,6 +31,8 @@ export {
|
|||||||
List,
|
List,
|
||||||
PlayButton,
|
PlayButton,
|
||||||
BatchPlayButton,
|
BatchPlayButton,
|
||||||
|
SongBulkActions,
|
||||||
|
AddToPlaylistButton,
|
||||||
SimpleList,
|
SimpleList,
|
||||||
RangeField,
|
RangeField,
|
||||||
SongDetails,
|
SongDetails,
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import React, { Fragment } from 'react'
|
|
||||||
import { BatchPlayButton } from '../common'
|
|
||||||
import AddToPlaylistButton from './AddToPlaylistButton'
|
|
||||||
import { RiPlayList2Fill } from 'react-icons/ri'
|
|
||||||
import { playNext } from '../audioplayer'
|
|
||||||
|
|
||||||
export const SongBulkActions = (props) => {
|
|
||||||
return (
|
|
||||||
<Fragment>
|
|
||||||
<BatchPlayButton
|
|
||||||
{...props}
|
|
||||||
action={playNext}
|
|
||||||
label={'resources.song.actions.playNext'}
|
|
||||||
icon={<RiPlayList2Fill />}
|
|
||||||
/>
|
|
||||||
<BatchPlayButton {...props} />
|
|
||||||
<AddToPlaylistButton {...props} />
|
|
||||||
</Fragment>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
} from '../common'
|
} from '../common'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { setTrack } from '../audioplayer'
|
import { setTrack } from '../audioplayer'
|
||||||
import { SongBulkActions } from './SongBulkActions'
|
import { SongBulkActions } from '../common'
|
||||||
import { SongListActions } from './SongListActions'
|
import { SongListActions } from './SongListActions'
|
||||||
import { AlbumLinkField } from './AlbumLinkField'
|
import { AlbumLinkField } from './AlbumLinkField'
|
||||||
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
import AddToPlaylistDialog from '../dialogs/AddToPlaylistDialog'
|
||||||
|
|||||||
Reference in New Issue
Block a user