fix: pass ordered song IDs to player actions and guard against undefined ids

- Pass allIds to dispatched actions so player knows track order
- Check ids is defined before comparing length to prevent crash during
  initial load when both ids and record.songCount are undefined

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Finomosec 2026-06-01 15:29:27 +02:00
parent edf5879523
commit 0f686a301c

View File

@ -62,7 +62,7 @@ const AlbumActions = ({
const getAllSongsAndDispatch = React.useCallback(
(action) => {
if (ids?.length === record.songCount) {
if (ids && ids.length === record.songCount) {
return dispatch(action(data, ids))
}
dataProvider
@ -76,7 +76,8 @@ const AlbumActions = ({
(acc, curr) => ({ ...acc, [curr.id]: curr }),
{},
)
dispatch(action(allData))
const allIds = res.data.map((s) => s.id)
dispatch(action(allData, allIds))
})
.catch(() => {
notify('ra.page.error', 'warning')
@ -102,7 +103,7 @@ const AlbumActions = ({
}, [getAllSongsAndDispatch])
const handleAddToPlaylist = React.useCallback(() => {
if (ids?.length === record.songCount) {
if (ids && ids.length === record.songCount) {
const selectedIds = ids.filter((id) => !data[id].missing)
return dispatch(openAddToPlaylist({ selectedIds }))
}