2021-05-24 07:09:06 -08:00
|
|
|
import React, { useMemo } from 'react'
|
2020-04-09 14:28:47 -08:00
|
|
|
import {
|
|
|
|
|
BulkActionsToolbar,
|
|
|
|
|
ListToolbar,
|
|
|
|
|
TextField,
|
2021-05-05 17:35:01 -08:00
|
|
|
NumberField,
|
2020-11-19 14:44:28 -09:00
|
|
|
useVersion,
|
|
|
|
|
useListContext,
|
2020-04-09 14:28:47 -08:00
|
|
|
} from 'react-admin'
|
2020-11-27 14:27:32 -09:00
|
|
|
import clsx from 'clsx'
|
2020-04-09 14:28:47 -08:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-05-15 09:48:33 -08:00
|
|
|
import { Card, useMediaQuery } from '@material-ui/core'
|
2020-04-09 14:28:47 -08:00
|
|
|
import { makeStyles } from '@material-ui/core/styles'
|
2021-03-26 19:56:19 -08:00
|
|
|
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder'
|
2020-11-08 09:15:46 -09:00
|
|
|
import { playTracks } from '../actions'
|
2020-05-22 16:15:58 -08:00
|
|
|
import {
|
|
|
|
|
DurationField,
|
2020-11-19 14:44:28 -09:00
|
|
|
SongBulkActions,
|
2020-06-13 12:39:57 -08:00
|
|
|
SongContextMenu,
|
2020-06-19 05:12:45 -08:00
|
|
|
SongDatagrid,
|
|
|
|
|
SongDetails,
|
|
|
|
|
SongTitleField,
|
2021-04-07 12:02:52 -08:00
|
|
|
RatingField,
|
2021-05-26 05:35:13 -08:00
|
|
|
QualityInfo,
|
|
|
|
|
useSelectedFields,
|
2021-06-10 08:20:52 -08:00
|
|
|
useResourceRefresh,
|
2020-05-22 16:15:58 -08:00
|
|
|
} from '../common'
|
2021-02-03 15:08:03 -09:00
|
|
|
import { AddToPlaylistDialog } from '../dialogs'
|
2021-03-28 16:35:49 -08:00
|
|
|
import config from '../config'
|
2020-04-09 14:28:47 -08:00
|
|
|
|
|
|
|
|
const useStyles = makeStyles(
|
|
|
|
|
(theme) => ({
|
|
|
|
|
root: {},
|
|
|
|
|
main: {
|
|
|
|
|
display: 'flex',
|
|
|
|
|
},
|
|
|
|
|
content: {
|
|
|
|
|
marginTop: 0,
|
|
|
|
|
transition: theme.transitions.create('margin-top'),
|
|
|
|
|
position: 'relative',
|
|
|
|
|
flex: '1 1 auto',
|
|
|
|
|
[theme.breakpoints.down('xs')]: {
|
|
|
|
|
boxShadow: 'none',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
bulkActionsDisplayed: {
|
|
|
|
|
marginTop: -theme.spacing(8),
|
|
|
|
|
transition: theme.transitions.create('margin-top'),
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
zIndex: 2,
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
},
|
|
|
|
|
noResults: { padding: 20 },
|
2020-05-24 08:12:12 -08:00
|
|
|
columnIcon: {
|
|
|
|
|
marginLeft: '3px',
|
2020-05-26 12:18:28 -08:00
|
|
|
marginTop: '-2px',
|
2020-05-24 08:12:12 -08:00
|
|
|
verticalAlign: 'text-top',
|
|
|
|
|
},
|
2020-11-19 14:44:28 -09:00
|
|
|
toolbar: {
|
|
|
|
|
justifyContent: 'flex-start',
|
|
|
|
|
},
|
2020-11-26 11:08:26 -09:00
|
|
|
row: {
|
|
|
|
|
'&:hover': {
|
|
|
|
|
'& $contextMenu': {
|
|
|
|
|
visibility: 'visible',
|
|
|
|
|
},
|
2021-04-07 12:02:52 -08:00
|
|
|
'& $ratingField': {
|
|
|
|
|
visibility: 'visible',
|
|
|
|
|
},
|
2020-11-26 11:08:26 -09:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
contextMenu: {
|
2020-11-27 19:52:23 -09:00
|
|
|
visibility: (props) => (props.isDesktop ? 'hidden' : 'visible'),
|
2020-11-26 11:08:26 -09:00
|
|
|
},
|
2021-04-07 12:02:52 -08:00
|
|
|
ratingField: {
|
|
|
|
|
visibility: 'hidden',
|
|
|
|
|
},
|
2020-04-09 14:28:47 -08:00
|
|
|
}),
|
|
|
|
|
{ name: 'RaList' }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const AlbumSongs = (props) => {
|
2020-11-26 13:00:53 -09:00
|
|
|
const { data, ids } = props
|
2020-04-14 10:59:16 -08:00
|
|
|
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
2020-04-09 14:28:47 -08:00
|
|
|
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
2020-11-27 19:52:23 -09:00
|
|
|
const classes = useStyles({ isDesktop })
|
|
|
|
|
const dispatch = useDispatch()
|
2020-11-19 14:44:28 -09:00
|
|
|
const version = useVersion()
|
2021-06-10 08:20:52 -08:00
|
|
|
useResourceRefresh('song', 'album')
|
2021-05-24 07:09:06 -08:00
|
|
|
|
|
|
|
|
const toggleableFields = useMemo(() => {
|
|
|
|
|
return {
|
|
|
|
|
trackNumber: isDesktop && (
|
|
|
|
|
<TextField
|
|
|
|
|
source="trackNumber"
|
|
|
|
|
sortBy="discNumber asc, trackNumber asc"
|
|
|
|
|
label="#"
|
|
|
|
|
sortable={false}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
title: (
|
|
|
|
|
<SongTitleField
|
|
|
|
|
source="title"
|
|
|
|
|
sortable={false}
|
|
|
|
|
showTrackNumbers={!isDesktop}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
artist: isDesktop && <TextField source="artist" sortable={false} />,
|
|
|
|
|
duration: <DurationField source="duration" sortable={false} />,
|
|
|
|
|
quality: isDesktop && <QualityInfo source="quality" sortable={false} />,
|
|
|
|
|
bpm: isDesktop && <NumberField source="bpm" sortable={false} />,
|
|
|
|
|
rating: isDesktop && config.enableStarRating && (
|
|
|
|
|
<RatingField
|
|
|
|
|
source="rating"
|
|
|
|
|
sortable={false}
|
|
|
|
|
className={classes.ratingField}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
}, [isDesktop, classes.ratingField])
|
|
|
|
|
|
|
|
|
|
const columns = useSelectedFields({
|
|
|
|
|
resource: 'albumSong',
|
|
|
|
|
columns: toggleableFields,
|
|
|
|
|
omittedColumns: ['title'],
|
|
|
|
|
defaultOff: ['bpm'],
|
|
|
|
|
})
|
|
|
|
|
|
2020-04-09 14:28:47 -08:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<ListToolbar
|
2020-11-19 14:44:28 -09:00
|
|
|
classes={{ toolbar: classes.toolbar }}
|
2020-04-09 14:28:47 -08:00
|
|
|
actions={props.actions}
|
2020-11-26 11:08:26 -09:00
|
|
|
{...props}
|
2020-04-09 14:28:47 -08:00
|
|
|
/>
|
|
|
|
|
<div className={classes.main}>
|
|
|
|
|
<Card
|
2020-11-27 14:27:32 -09:00
|
|
|
className={clsx(classes.content, {
|
2020-11-26 11:08:26 -09:00
|
|
|
[classes.bulkActionsDisplayed]: props.selectedIds.length > 0,
|
2020-04-09 14:28:47 -08:00
|
|
|
})}
|
|
|
|
|
key={version}
|
|
|
|
|
>
|
2020-11-26 11:08:26 -09:00
|
|
|
<BulkActionsToolbar {...props}>
|
2020-11-19 14:44:28 -09:00
|
|
|
<SongBulkActions />
|
|
|
|
|
</BulkActionsToolbar>
|
|
|
|
|
<SongDatagrid
|
|
|
|
|
expand={isXsmall ? null : <SongDetails />}
|
|
|
|
|
rowClick={(id) => dispatch(playTracks(data, ids, id))}
|
2020-11-26 11:08:26 -09:00
|
|
|
{...props}
|
2020-11-19 14:44:28 -09:00
|
|
|
hasBulkActions={true}
|
|
|
|
|
showDiscSubtitles={true}
|
|
|
|
|
contextAlwaysVisible={!isDesktop}
|
2020-11-26 11:08:26 -09:00
|
|
|
classes={{ row: classes.row }}
|
2020-11-19 14:44:28 -09:00
|
|
|
>
|
2021-05-24 07:09:06 -08:00
|
|
|
{columns}
|
2020-11-19 14:44:28 -09:00
|
|
|
<SongContextMenu
|
|
|
|
|
source={'starred'}
|
|
|
|
|
sortable={false}
|
2020-11-26 11:08:26 -09:00
|
|
|
className={classes.contextMenu}
|
2020-11-19 14:44:28 -09:00
|
|
|
label={
|
2021-03-28 16:35:49 -08:00
|
|
|
config.enableFavourites && (
|
|
|
|
|
<FavoriteBorderIcon
|
|
|
|
|
fontSize={'small'}
|
|
|
|
|
className={classes.columnIcon}
|
|
|
|
|
/>
|
|
|
|
|
)
|
2020-11-19 14:44:28 -09:00
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</SongDatagrid>
|
2020-04-09 14:28:47 -08:00
|
|
|
</Card>
|
|
|
|
|
</div>
|
2020-05-28 04:16:31 -08:00
|
|
|
<AddToPlaylistDialog />
|
2020-04-09 14:28:47 -08:00
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 17:40:55 -08:00
|
|
|
export const removeAlbumCommentsFromSongs = ({ album, data }) => {
|
|
|
|
|
if (album?.comment && data) {
|
|
|
|
|
Object.values(data).forEach((song) => {
|
|
|
|
|
song.comment = ''
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 14:44:28 -09:00
|
|
|
const SanitizedAlbumSongs = (props) => {
|
2021-04-24 17:40:55 -08:00
|
|
|
removeAlbumCommentsFromSongs(props)
|
|
|
|
|
|
2020-11-19 14:44:28 -09:00
|
|
|
const { loaded, loading, total, ...rest } = useListContext(props)
|
|
|
|
|
return <>{loaded && <AlbumSongs {...rest} actions={props.actions} />}</>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default SanitizedAlbumSongs
|