From a7640c9df47199bfb322cfda991a079c3d6e4640 Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 29 May 2020 16:59:38 -0400 Subject: [PATCH] Optimized call to retrieve album songs --- ui/src/common/AlbumContextMenu.js | 23 +++++++++-------------- ui/src/common/SongContextMenu.js | 8 ++++---- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/ui/src/common/AlbumContextMenu.js b/ui/src/common/AlbumContextMenu.js index e1ce0beb4..c0bd72f5a 100644 --- a/ui/src/common/AlbumContextMenu.js +++ b/ui/src/common/AlbumContextMenu.js @@ -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) => ( - {options[key].label} + {translate(options[key].label)} ))} diff --git a/ui/src/common/SongContextMenu.js b/ui/src/common/SongContextMenu.js index 62faaf759..4be70f593 100644 --- a/ui/src/common/SongContextMenu.js +++ b/ui/src/common/SongContextMenu.js @@ -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) => ( - {options[key].label} + {translate(options[key].label)} ))}