navidrome/ui/src/common/PlayButton.jsx
Deluan Quintão ed7ee3d9f8
fix(ui): always order album tracks by disc and track number (fixes #3720) (#3975)
* fix(ui): ensure album tracks are always ordered by disc and track number (fixes #3720)

* refactor(ui): remove obsolete release date grouping logic from SongDatagrid and AlbumSongs

* fix(ui): ensure correct album track ordering in context menu and play button

* fix: Update album sort to use album_id instead of release_date

* refactor: Adjust filters in PlayButton and AlbumContextMenu

* fix: correct typo in comment regarding participants in GetMissingAndMatching function

* fix: prevent visual separation of tracks on same disc

Removes the leftover `releaseDate` check from the `firstTracksOfDiscs` calculation in `SongDatagridBody`. This check caused unnecessary `DiscSubtitleRow` insertions when tracks on the same disc had different release dates, leading to an incorrect visual grouping that resembled a multi-disc layout.

This change ensures disc subtitles are only shown when the actual `discNumber` changes, correcting the UI presentation issue reported in issue #3720 after PR #3975.

* fix: remove remaining releaseDate references in SongDatagrid

Cleaned up leftover `releaseDate` references in `SongDatagrid.jsx`:

- Removed `releaseDate` parameter and usage from `handlePlaySubset` in `DiscSubtitleRow`.

- Removed `releaseDate` prop passed to `AlbumContextMenu` in `DiscSubtitleRow`.

- Removed `releaseDate` from the drag item data in `SongDatagridRow`.

- Removed `releaseDate` parameter and the corresponding `else` block from the `playSubset` function in `SongDatagridBody`.

This ensures the component consistently uses `discNumber` for grouping and playback actions initiated from the disc subtitle, fully resolving the inconsistencies related to issue #3720.
2025-04-17 19:23:53 -04:00

61 lines
1.5 KiB
JavaScript

import React from 'react'
import PropTypes from 'prop-types'
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
import { IconButton } from '@material-ui/core'
import { useDispatch } from 'react-redux'
import { useDataProvider } from 'react-admin'
import { playTracks } from '../actions'
export const PlayButton = ({ record, size, className }) => {
let extractSongsData = function (response) {
const data = response.data.reduce(
(acc, cur) => ({ ...acc, [cur.id]: cur }),
{},
)
const ids = response.data.map((r) => r.id)
return { data, ids }
}
const dataProvider = useDataProvider()
const dispatch = useDispatch()
const playAlbum = (record) => {
dataProvider
.getList('song', {
pagination: { page: 1, perPage: -1 },
sort: { field: 'album', order: 'ASC' },
filter: {
album_id: record.id,
disc_number: record.discNumber,
},
})
.then((response) => {
let { data, ids } = extractSongsData(response)
dispatch(playTracks(data, ids))
})
}
return (
<IconButton
onClick={(e) => {
e.stopPropagation()
e.preventDefault()
playAlbum(record)
}}
aria-label="play"
className={className}
size={size}
>
<PlayArrowIcon fontSize={size} />
</IconButton>
)
}
PlayButton.propTypes = {
record: PropTypes.object.isRequired,
size: PropTypes.string,
className: PropTypes.string,
}
PlayButton.defaultProps = {
size: 'small',
}