2020-02-12 16:35:35 -09:00
|
|
|
import React from 'react'
|
2020-01-22 06:19:13 -09:00
|
|
|
import {
|
|
|
|
|
Filter,
|
2020-03-30 15:34:00 -08:00
|
|
|
FunctionField,
|
2020-01-22 06:19:13 -09:00
|
|
|
NumberField,
|
|
|
|
|
SearchInput,
|
2020-04-16 06:26:24 -08:00
|
|
|
TextField,
|
2020-01-22 06:19:13 -09:00
|
|
|
} from 'react-admin'
|
2020-02-05 14:16:00 -09:00
|
|
|
import { useMediaQuery } from '@material-ui/core'
|
2020-05-24 08:12:12 -08:00
|
|
|
import StarIcon from '@material-ui/icons/Star'
|
2020-05-22 16:15:58 -08:00
|
|
|
import {
|
|
|
|
|
DurationField,
|
|
|
|
|
List,
|
|
|
|
|
SongContextMenu,
|
2020-05-23 09:23:00 -08:00
|
|
|
SongDatagrid,
|
|
|
|
|
SongDetails,
|
|
|
|
|
QuickFilter,
|
2020-06-19 05:12:45 -08:00
|
|
|
SongTitleField,
|
2021-03-22 20:12:19 -08:00
|
|
|
SongSimpleList,
|
2020-05-22 16:15:58 -08:00
|
|
|
} from '../common'
|
2020-02-06 08:54:27 -09:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-11-08 09:15:46 -09:00
|
|
|
import { setTrack } from '../actions'
|
2020-10-31 06:23:52 -08:00
|
|
|
import { SongBulkActions } from '../common'
|
2020-08-07 06:47:55 -08:00
|
|
|
import { SongListActions } from './SongListActions'
|
2020-03-30 15:34:00 -08:00
|
|
|
import { AlbumLinkField } from './AlbumLinkField'
|
2021-02-03 15:08:03 -09:00
|
|
|
import { AddToPlaylistDialog } from '../dialogs'
|
2020-11-26 11:08:26 -09:00
|
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
|
|
|
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
|
|
|
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
|
|
contextHeader: {
|
|
|
|
|
marginLeft: '3px',
|
|
|
|
|
marginTop: '-2px',
|
|
|
|
|
verticalAlign: 'text-top',
|
|
|
|
|
},
|
|
|
|
|
row: {
|
|
|
|
|
'&:hover': {
|
|
|
|
|
'& $contextMenu': {
|
|
|
|
|
visibility: 'visible',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
contextMenu: {
|
|
|
|
|
visibility: 'hidden',
|
|
|
|
|
},
|
|
|
|
|
})
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
const SongFilter = (props) => (
|
2020-08-17 07:19:39 -08:00
|
|
|
<Filter {...props} variant={'outlined'}>
|
2020-01-22 06:19:13 -09:00
|
|
|
<SearchInput source="title" alwaysOn />
|
2020-05-24 08:12:12 -08:00
|
|
|
<QuickFilter
|
|
|
|
|
source="starred"
|
|
|
|
|
label={<StarIcon fontSize={'small'} />}
|
|
|
|
|
defaultValue={true}
|
|
|
|
|
/>
|
2020-01-22 06:19:13 -09:00
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const SongList = (props) => {
|
2020-11-26 11:08:26 -09:00
|
|
|
const classes = useStyles()
|
2020-02-06 08:54:27 -09:00
|
|
|
const dispatch = useDispatch()
|
2020-02-05 14:16:00 -09:00
|
|
|
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
2020-02-06 08:54:27 -09:00
|
|
|
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
2020-05-31 10:27:02 -08:00
|
|
|
|
|
|
|
|
const handleRowClick = (id, basePath, record) => {
|
|
|
|
|
dispatch(setTrack(record))
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
return (
|
2020-05-25 14:34:31 -08:00
|
|
|
<>
|
|
|
|
|
<List
|
|
|
|
|
{...props}
|
|
|
|
|
sort={{ field: 'title', order: 'ASC' }}
|
|
|
|
|
exporter={false}
|
|
|
|
|
bulkActionButtons={<SongBulkActions />}
|
2020-08-07 06:47:55 -08:00
|
|
|
actions={<SongListActions />}
|
2020-05-25 14:34:31 -08:00
|
|
|
filters={<SongFilter />}
|
|
|
|
|
perPage={isXsmall ? 50 : 15}
|
|
|
|
|
>
|
|
|
|
|
{isXsmall ? (
|
2021-03-22 20:12:19 -08:00
|
|
|
<SongSimpleList />
|
2020-05-25 14:34:31 -08:00
|
|
|
) : (
|
|
|
|
|
<SongDatagrid
|
|
|
|
|
expand={<SongDetails />}
|
2020-05-31 10:27:02 -08:00
|
|
|
rowClick={handleRowClick}
|
2020-05-26 18:02:15 -08:00
|
|
|
contextAlwaysVisible={!isDesktop}
|
2020-11-26 11:08:26 -09:00
|
|
|
classes={{ row: classes.row }}
|
2020-05-25 14:34:31 -08:00
|
|
|
>
|
2020-06-19 05:12:45 -08:00
|
|
|
<SongTitleField source="title" showTrackNumbers={false} />
|
2020-12-23 07:38:40 -09:00
|
|
|
{isDesktop && (
|
|
|
|
|
<AlbumLinkField
|
|
|
|
|
source="album"
|
|
|
|
|
sortBy={
|
|
|
|
|
'album, order_album_artist_name, disc_number, track_number, title'
|
|
|
|
|
}
|
|
|
|
|
sortByOrder={'ASC'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-05-25 14:34:31 -08:00
|
|
|
<TextField source="artist" />
|
|
|
|
|
{isDesktop && <NumberField source="trackNumber" />}
|
|
|
|
|
{isDesktop && (
|
2020-06-09 03:45:23 -08:00
|
|
|
<NumberField source="playCount" sortByOrder={'DESC'} />
|
|
|
|
|
)}
|
|
|
|
|
{isDesktop && (
|
|
|
|
|
<FunctionField
|
|
|
|
|
source="year"
|
|
|
|
|
render={(r) => r.year || ''}
|
|
|
|
|
sortByOrder={'DESC'}
|
|
|
|
|
/>
|
2020-05-25 14:34:31 -08:00
|
|
|
)}
|
|
|
|
|
<DurationField source="duration" />
|
2020-05-26 18:02:15 -08:00
|
|
|
<SongContextMenu
|
|
|
|
|
source={'starred'}
|
2020-06-09 03:45:23 -08:00
|
|
|
sortBy={'starred ASC, starredAt ASC'}
|
|
|
|
|
sortByOrder={'DESC'}
|
2020-11-26 11:08:26 -09:00
|
|
|
className={classes.contextMenu}
|
|
|
|
|
label={
|
|
|
|
|
<StarBorderIcon
|
|
|
|
|
fontSize={'small'}
|
|
|
|
|
className={classes.contextHeader}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
textAlign={'right'}
|
2020-05-26 18:02:15 -08:00
|
|
|
/>
|
2020-05-25 14:34:31 -08:00
|
|
|
</SongDatagrid>
|
|
|
|
|
)}
|
|
|
|
|
</List>
|
2020-05-28 04:16:31 -08:00
|
|
|
<AddToPlaylistDialog />
|
2020-05-25 14:34:31 -08:00
|
|
|
</>
|
2020-02-04 05:26:54 -09:00
|
|
|
)
|
|
|
|
|
}
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
export default SongList
|