Add download for songs
This commit is contained in:
@@ -35,22 +35,27 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
|
||||
const options = {
|
||||
play: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.playAll',
|
||||
action: (data, ids) => dispatch(playTracks(data, ids)),
|
||||
},
|
||||
addToQueue: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.addToQueue',
|
||||
action: (data, ids) => dispatch(addTracks(data, ids)),
|
||||
},
|
||||
shuffle: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.shuffle',
|
||||
action: (data, ids) => dispatch(shuffleTracks(data, ids)),
|
||||
},
|
||||
addToPlaylist: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.addToPlaylist',
|
||||
action: (data, ids) => dispatch(openAddToPlaylist({ selectedIds: ids })),
|
||||
},
|
||||
download: {
|
||||
needData: false,
|
||||
label: 'resources.album.actions.download',
|
||||
action: () => subsonic.download(record.id),
|
||||
},
|
||||
@@ -80,19 +85,23 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
const handleItemClick = (e) => {
|
||||
setAnchorEl(null)
|
||||
const key = e.target.getAttribute('value')
|
||||
dataProvider
|
||||
.getList('albumSong', {
|
||||
pagination: { page: 1, perPage: -1 },
|
||||
sort: { field: 'discNumber, trackNumber', order: 'ASC' },
|
||||
filter: { album_id: record.id, disc_number: discNumber },
|
||||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response)
|
||||
options[key].action(data, ids)
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
})
|
||||
if (options[key].needData) {
|
||||
dataProvider
|
||||
.getList('albumSong', {
|
||||
pagination: { page: 1, perPage: -1 },
|
||||
sort: { field: 'discNumber, trackNumber', order: 'ASC' },
|
||||
filter: { album_id: record.id, disc_number: discNumber },
|
||||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response)
|
||||
options[key].action(data, ids)
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
})
|
||||
} else {
|
||||
options[key].action()
|
||||
}
|
||||
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import StarIcon from '@material-ui/icons/Star'
|
||||
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||
import { addTracks, setTrack } from '../audioplayer'
|
||||
import { openAddToPlaylist } from '../dialogs/dialogState'
|
||||
import subsonic from '../subsonic'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
noWrap: {
|
||||
@@ -39,19 +40,25 @@ const SongContextMenu = ({
|
||||
const options = {
|
||||
playNow: {
|
||||
label: 'resources.song.actions.playNow',
|
||||
action: (record) => setTrack(record),
|
||||
action: (record) => dispatch(setTrack(record)),
|
||||
},
|
||||
addToQueue: {
|
||||
label: 'resources.song.actions.addToQueue',
|
||||
action: (record) => addTracks({ [record.id]: record }),
|
||||
action: (record) => dispatch(addTracks({ [record.id]: record })),
|
||||
},
|
||||
addToPlaylist: {
|
||||
label: 'resources.song.actions.addToPlaylist',
|
||||
action: (record) =>
|
||||
openAddToPlaylist({
|
||||
selectedIds: [record.mediaFileId || record.id],
|
||||
onSuccess: (id) => onAddToPlaylist(id),
|
||||
}),
|
||||
dispatch(
|
||||
openAddToPlaylist({
|
||||
selectedIds: [record.mediaFileId || record.id],
|
||||
onSuccess: (id) => onAddToPlaylist(id),
|
||||
})
|
||||
),
|
||||
},
|
||||
download: {
|
||||
label: 'resources.song.actions.download',
|
||||
action: (record) => subsonic.download(record.id),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -69,7 +76,7 @@ const SongContextMenu = ({
|
||||
e.preventDefault()
|
||||
setAnchorEl(null)
|
||||
const key = e.target.getAttribute('value')
|
||||
dispatch(options[key].action(record))
|
||||
options[key].action(record)
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user