Add 'download' option to album context menu
This commit is contained in:
parent
8e4b2e1c06
commit
38c19eddc3
|
@ -44,7 +44,9 @@
|
|||
"playAll": "Tocar",
|
||||
"playNext": "Tocar em seguida",
|
||||
"addToQueue": "Adicionar à fila",
|
||||
"shuffle": "Aleatório"
|
||||
"shuffle": "Aleatório",
|
||||
"addToPlaylist": "Adicionar à playlist",
|
||||
"download": "Baixar"
|
||||
},
|
||||
"lists": {
|
||||
"all": "Todos",
|
||||
|
|
|
@ -6,11 +6,14 @@ import {
|
|||
} from 'react-admin'
|
||||
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
||||
import ShuffleIcon from '@material-ui/icons/Shuffle'
|
||||
import CloudDownloadIcon from '@material-ui/icons/CloudDownload'
|
||||
import React from 'react'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { playTracks, shuffleTracks } from '../audioplayer'
|
||||
import subsonic from '../subsonic'
|
||||
|
||||
const AlbumActions = ({
|
||||
albumId,
|
||||
className,
|
||||
ids,
|
||||
data,
|
||||
|
@ -21,6 +24,7 @@ const AlbumActions = ({
|
|||
const dispatch = useDispatch()
|
||||
const translate = useTranslate()
|
||||
|
||||
console.log(rest)
|
||||
return (
|
||||
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
||||
<Button
|
||||
|
@ -39,6 +43,14 @@ const AlbumActions = ({
|
|||
>
|
||||
<ShuffleIcon />
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
subsonic.download(albumId)
|
||||
}}
|
||||
label={translate('resources.album.actions.download')}
|
||||
>
|
||||
<CloudDownloadIcon />
|
||||
</Button>
|
||||
</TopToolbar>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ const AlbumShow = (props) => {
|
|||
{...props}
|
||||
albumId={props.id}
|
||||
title={<Title subTitle={record.name} />}
|
||||
actions={<AlbumActions />}
|
||||
actions={<AlbumActions albumId={props.id} />}
|
||||
filter={{ album_id: props.id }}
|
||||
resource={'albumSong'}
|
||||
exporter={false}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import React, { useState } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import IconButton from '@material-ui/core/IconButton'
|
||||
import Menu from '@material-ui/core/Menu'
|
||||
import MenuItem from '@material-ui/core/MenuItem'
|
||||
import MoreVertIcon from '@material-ui/icons/MoreVert'
|
||||
import StarIcon from '@material-ui/icons/Star'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import { useDataProvider, useNotify, useTranslate } from 'react-admin'
|
||||
import { addTracks, playTracks, shuffleTracks } from '../audioplayer'
|
||||
import { openAddToPlaylist } from '../dialogs/dialogState'
|
||||
import StarIcon from '@material-ui/icons/Star'
|
||||
import PropTypes from 'prop-types'
|
||||
import subsonic from '../subsonic'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
noWrap: {
|
||||
|
@ -35,19 +36,23 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
|||
const options = {
|
||||
play: {
|
||||
label: 'resources.album.actions.playAll',
|
||||
action: playTracks,
|
||||
action: (data, ids) => dispatch(playTracks(data, ids)),
|
||||
},
|
||||
addToQueue: {
|
||||
label: 'resources.album.actions.addToQueue',
|
||||
action: addTracks,
|
||||
action: (data, ids) => dispatch(addTracks(data, ids)),
|
||||
},
|
||||
shuffle: {
|
||||
label: 'resources.album.actions.shuffle',
|
||||
action: shuffleTracks,
|
||||
action: (data, ids) => dispatch(shuffleTracks(data, ids)),
|
||||
},
|
||||
addToPlaylist: {
|
||||
label: 'resources.song.actions.addToPlaylist',
|
||||
action: (data, ids) => openAddToPlaylist({ selectedIds: ids }),
|
||||
label: 'resources.album.actions.addToPlaylist',
|
||||
action: (data, ids) => dispatch(openAddToPlaylist({ selectedIds: ids })),
|
||||
},
|
||||
download: {
|
||||
label: 'resources.album.actions.download',
|
||||
action: () => subsonic.download(record.id),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -83,7 +88,7 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
|||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response)
|
||||
dispatch(options[key].action(data, ids))
|
||||
options[key].action(data, ids)
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
|
|
|
@ -45,7 +45,9 @@
|
|||
"playAll": "Play",
|
||||
"playNext": "Play Next",
|
||||
"addToQueue": "Play Later",
|
||||
"shuffle": "Shuffle"
|
||||
"shuffle": "Shuffle",
|
||||
"addToPlaylist": "Add to Playlist",
|
||||
"download": "Download"
|
||||
},
|
||||
"lists": {
|
||||
"all": "All",
|
||||
|
|
|
@ -26,4 +26,6 @@ const url = (command, id, options) => {
|
|||
const scrobble = (id, submit) =>
|
||||
fetchUtils.fetchJson(url('scrobble', id, { submission: submit }))
|
||||
|
||||
export default { url, scrobble }
|
||||
const download = (id, submit) => (window.location.href = url('download', id))
|
||||
|
||||
export default { url, scrobble, download }
|
||||
|
|
Loading…
Reference in New Issue