mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-06 13:21:08 +03:00
Optimized call to retrieve album songs
This commit is contained in:
parent
8f8d992da4
commit
a7640c9df4
@ -34,19 +34,19 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
|
||||
const options = {
|
||||
play: {
|
||||
label: translate('resources.album.actions.playAll'),
|
||||
label: 'resources.album.actions.playAll',
|
||||
action: playTracks,
|
||||
},
|
||||
addToQueue: {
|
||||
label: translate('resources.album.actions.addToQueue'),
|
||||
label: 'resources.album.actions.addToQueue',
|
||||
action: addTracks,
|
||||
},
|
||||
shuffle: {
|
||||
label: translate('resources.album.actions.shuffle'),
|
||||
label: 'resources.album.actions.shuffle',
|
||||
action: shuffleTracks,
|
||||
},
|
||||
addToPlaylist: {
|
||||
label: translate('resources.song.actions.addToPlaylist'),
|
||||
label: 'resources.song.actions.addToPlaylist',
|
||||
action: (data, ids) => openAddToPlaylist({ selectedIds: ids }),
|
||||
},
|
||||
}
|
||||
@ -63,17 +63,12 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
let extractSongsData = function (response, discNumber) {
|
||||
let extractSongsData = function (response) {
|
||||
const data = response.data.reduce(
|
||||
(acc, cur) => ({ ...acc, [cur.id]: cur }),
|
||||
{}
|
||||
)
|
||||
|
||||
const ids = response.data
|
||||
// Select only songs from discNumber if it is specified
|
||||
.filter((r) => !discNumber || r.discNumber === discNumber)
|
||||
.map((r) => r.id)
|
||||
|
||||
const ids = response.data.map((r) => r.id)
|
||||
return { data, ids }
|
||||
}
|
||||
|
||||
@ -84,10 +79,10 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
.getList('albumSong', {
|
||||
pagination: { page: 1, perPage: -1 },
|
||||
sort: { field: 'discNumber, trackNumber', order: 'ASC' },
|
||||
filter: { album_id: record.id },
|
||||
filter: { album_id: record.id, disc_number: discNumber },
|
||||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response, discNumber)
|
||||
let { data, ids } = extractSongsData(response)
|
||||
dispatch(options[key].action(data, ids))
|
||||
})
|
||||
.catch(() => {
|
||||
@ -123,7 +118,7 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
>
|
||||
{Object.keys(options).map((key) => (
|
||||
<MenuItem value={key} key={key} onClick={handleItemClick}>
|
||||
{options[key].label}
|
||||
{translate(options[key].label)}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
|
@ -39,15 +39,15 @@ const SongContextMenu = ({
|
||||
const [anchorEl, setAnchorEl] = useState(null)
|
||||
const options = {
|
||||
playNow: {
|
||||
label: translate('resources.song.actions.playNow'),
|
||||
label: 'resources.song.actions.playNow',
|
||||
action: (record) => setTrack(record),
|
||||
},
|
||||
addToQueue: {
|
||||
label: translate('resources.song.actions.addToQueue'),
|
||||
label: 'resources.song.actions.addToQueue',
|
||||
action: (record) => addTracks({ [record.id]: record }),
|
||||
},
|
||||
addToPlaylist: {
|
||||
label: translate('resources.song.actions.addToPlaylist'),
|
||||
label: 'resources.song.actions.addToPlaylist',
|
||||
action: (record) =>
|
||||
openAddToPlaylist({
|
||||
selectedIds: [record.mediaFileId || record.id],
|
||||
@ -130,7 +130,7 @@ const SongContextMenu = ({
|
||||
>
|
||||
{Object.keys(options).map((key) => (
|
||||
<MenuItem value={key} key={key} onClick={handleItemClick}>
|
||||
{options[key].label}
|
||||
{translate(options[key].label)}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
|
Loading…
x
Reference in New Issue
Block a user