mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-12 21:32:17 +03:00
Refactor: move multiDisc detection logic to SongDatagrid
This commit is contained in:
parent
915b701e44
commit
ba8c8725dd
@ -78,16 +78,7 @@ const AlbumSongs = (props) => {
|
|||||||
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
||||||
const controllerProps = useListController(props)
|
const controllerProps = useListController(props)
|
||||||
const { bulkActionButtons, albumId, className } = props
|
const { bulkActionButtons, albumId, className } = props
|
||||||
const { data, ids, version, loaded } = controllerProps
|
const { data, ids, version } = controllerProps
|
||||||
|
|
||||||
let multiDisc = false
|
|
||||||
if (loaded) {
|
|
||||||
const discNumbers = ids
|
|
||||||
.map((id) => data[id])
|
|
||||||
.filter((r) => r)
|
|
||||||
.map((r) => r.discNumber)
|
|
||||||
multiDisc = new Set(discNumbers).size > 1
|
|
||||||
}
|
|
||||||
|
|
||||||
const anySong = data[ids[0]]
|
const anySong = data[ids[0]]
|
||||||
const showPlaceholder = !anySong || anySong.albumId !== albumId
|
const showPlaceholder = !anySong || anySong.albumId !== albumId
|
||||||
@ -130,7 +121,7 @@ const AlbumSongs = (props) => {
|
|||||||
rowClick={(id) => dispatch(playTracks(data, ids, id))}
|
rowClick={(id) => dispatch(playTracks(data, ids, id))}
|
||||||
{...controllerProps}
|
{...controllerProps}
|
||||||
hasBulkActions={hasBulkActions}
|
hasBulkActions={hasBulkActions}
|
||||||
multiDisc={multiDisc}
|
showDiscSubtitles={true}
|
||||||
contextAlwaysVisible={!isDesktop}
|
contextAlwaysVisible={!isDesktop}
|
||||||
>
|
>
|
||||||
{isDesktop && (
|
{isDesktop && (
|
||||||
|
@ -24,7 +24,7 @@ const useStyles = makeStyles({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const DiscSubtitleRow = ({ record, onClickDiscSubtitle, length }) => {
|
const DiscSubtitleRow = ({ record, onClickDiscSubtitle, colSpan }) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [visible, setVisible] = useState(false)
|
const [visible, setVisible] = useState(false)
|
||||||
const handlePlayDisc = (discNumber) => () => {
|
const handlePlayDisc = (discNumber) => () => {
|
||||||
@ -38,7 +38,7 @@ const DiscSubtitleRow = ({ record, onClickDiscSubtitle, length }) => {
|
|||||||
onMouseLeave={() => setVisible(false)}
|
onMouseLeave={() => setVisible(false)}
|
||||||
className={classes.row}
|
className={classes.row}
|
||||||
>
|
>
|
||||||
<TableCell colSpan={length}>
|
<TableCell colSpan={colSpan}>
|
||||||
<Typography variant="h6" className={classes.subtitle}>
|
<Typography variant="h6" className={classes.subtitle}>
|
||||||
<AlbumIcon className={classes.discIcon} fontSize={'small'} />
|
<AlbumIcon className={classes.discIcon} fontSize={'small'} />
|
||||||
{record.discNumber}
|
{record.discNumber}
|
||||||
@ -73,7 +73,7 @@ export const SongDatagridRow = ({
|
|||||||
<DiscSubtitleRow
|
<DiscSubtitleRow
|
||||||
record={record}
|
record={record}
|
||||||
onClickDiscSubtitle={onClickDiscSubtitle}
|
onClickDiscSubtitle={onClickDiscSubtitle}
|
||||||
length={childCount}
|
colSpan={childCount}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<DatagridRow
|
<DatagridRow
|
||||||
@ -111,12 +111,28 @@ SongDatagridRow.defaultProps = {
|
|||||||
onClickDiscSubtitle: () => {},
|
onClickDiscSubtitle: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SongDatagrid = ({ multiDisc, contextAlwaysVisible, ...rest }) => {
|
export const SongDatagrid = ({
|
||||||
|
contextAlwaysVisible,
|
||||||
|
showDiscSubtitles,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
const { ids, data } = rest
|
||||||
|
|
||||||
const playDisc = (discNumber) => {
|
const playDisc = (discNumber) => {
|
||||||
const ids = rest.ids.filter((id) => rest.data[id].discNumber === discNumber)
|
const idsToPlay = ids.filter((id) => data[id].discNumber === discNumber)
|
||||||
dispatch(playTracks(rest.data, ids))
|
dispatch(playTracks(data, idsToPlay))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const multiDisc =
|
||||||
|
showDiscSubtitles &&
|
||||||
|
new Set(
|
||||||
|
ids
|
||||||
|
.map((id) => data[id])
|
||||||
|
.filter((r) => r) // remove null records
|
||||||
|
.map((r) => r.discNumber)
|
||||||
|
).size > 1
|
||||||
|
|
||||||
const SongDatagridBody = (props) => (
|
const SongDatagridBody = (props) => (
|
||||||
<DatagridBody
|
<DatagridBody
|
||||||
{...props}
|
{...props}
|
||||||
@ -134,5 +150,5 @@ export const SongDatagrid = ({ multiDisc, contextAlwaysVisible, ...rest }) => {
|
|||||||
|
|
||||||
SongDatagrid.propTypes = {
|
SongDatagrid.propTypes = {
|
||||||
contextAlwaysVisible: PropTypes.bool,
|
contextAlwaysVisible: PropTypes.bool,
|
||||||
multiDisc: PropTypes.bool,
|
showDiscSubtitles: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user