2020-02-12 16:35:35 -09:00
|
|
|
import React from 'react'
|
2020-01-22 06:19:13 -09:00
|
|
|
import {
|
|
|
|
|
Datagrid,
|
|
|
|
|
Filter,
|
2020-03-30 15:34:00 -08:00
|
|
|
FunctionField,
|
2020-01-22 06:19:13 -09:00
|
|
|
List,
|
|
|
|
|
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-02-12 16:35:35 -09:00
|
|
|
import {
|
|
|
|
|
DurationField,
|
|
|
|
|
Pagination,
|
|
|
|
|
PlayButton,
|
|
|
|
|
SimpleList,
|
|
|
|
|
Title,
|
|
|
|
|
} from '../common'
|
2020-02-06 08:54:27 -09:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-03-11 15:46:46 -08:00
|
|
|
import { addTrack, setTrack } from '../audioplayer'
|
2020-02-06 08:54:27 -09:00
|
|
|
import AddIcon from '@material-ui/icons/Add'
|
2020-02-12 16:35:35 -09:00
|
|
|
import { SongBulkActions } from './SongBulkActions'
|
2020-03-30 15:34:00 -08:00
|
|
|
import { AlbumLinkField } from './AlbumLinkField'
|
2020-04-14 10:59:16 -08:00
|
|
|
import { SongDetails } from '../common'
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
const SongFilter = (props) => (
|
|
|
|
|
<Filter {...props}>
|
|
|
|
|
<SearchInput source="title" alwaysOn />
|
|
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const SongList = (props) => {
|
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-02-04 05:26:54 -09:00
|
|
|
return (
|
|
|
|
|
<List
|
|
|
|
|
{...props}
|
2020-04-27 19:22:17 -08:00
|
|
|
title={
|
|
|
|
|
<Title subTitle={'resources.song.name'} args={{ smart_count: 2 }} />
|
|
|
|
|
}
|
2020-02-04 05:26:54 -09:00
|
|
|
sort={{ field: 'title', order: 'ASC' }}
|
|
|
|
|
exporter={false}
|
2020-02-12 16:35:35 -09:00
|
|
|
bulkActionButtons={<SongBulkActions />}
|
2020-02-04 05:26:54 -09:00
|
|
|
filters={<SongFilter />}
|
2020-02-06 08:54:27 -09:00
|
|
|
perPage={isXsmall ? 50 : 15}
|
2020-02-05 09:28:39 -09:00
|
|
|
pagination={<Pagination />}
|
2020-02-04 05:26:54 -09:00
|
|
|
>
|
2020-02-05 14:16:00 -09:00
|
|
|
{isXsmall ? (
|
|
|
|
|
<SimpleList
|
2020-02-07 12:38:01 -09:00
|
|
|
primaryText={(r) => (
|
2020-02-05 14:16:00 -09:00
|
|
|
<>
|
2020-02-07 12:38:01 -09:00
|
|
|
<PlayButton action={setTrack(r)} />
|
|
|
|
|
<PlayButton action={addTrack(r)} icon={<AddIcon />} />
|
|
|
|
|
{r.title}
|
2020-02-05 14:16:00 -09:00
|
|
|
</>
|
|
|
|
|
)}
|
2020-02-07 12:38:01 -09:00
|
|
|
secondaryText={(r) => r.artist}
|
|
|
|
|
tertiaryText={(r) => <DurationField record={r} source={'duration'} />}
|
2020-02-07 11:35:05 -09:00
|
|
|
linkType={(id, basePath, record) => dispatch(setTrack(record))}
|
2020-02-05 14:16:00 -09:00
|
|
|
/>
|
|
|
|
|
) : (
|
2020-02-06 08:54:27 -09:00
|
|
|
<Datagrid
|
|
|
|
|
expand={<SongDetails />}
|
|
|
|
|
rowClick={(id, basePath, record) => dispatch(setTrack(record))}
|
|
|
|
|
>
|
2020-02-05 14:16:00 -09:00
|
|
|
<TextField source="title" />
|
2020-04-24 13:37:28 -08:00
|
|
|
{isDesktop && <AlbumLinkField source="album" />}
|
|
|
|
|
<TextField source="artist" />
|
2020-02-07 05:40:52 -09:00
|
|
|
{isDesktop && <NumberField source="trackNumber" />}
|
2020-03-28 16:38:41 -08:00
|
|
|
{isDesktop && <NumberField source="playCount" />}
|
|
|
|
|
{isDesktop && (
|
|
|
|
|
<FunctionField source="year" render={(r) => r.year || ''} />
|
|
|
|
|
)}
|
2020-02-07 05:40:52 -09:00
|
|
|
<DurationField source="duration" />
|
2020-02-05 14:16:00 -09:00
|
|
|
</Datagrid>
|
|
|
|
|
)}
|
2020-02-04 05:26:54 -09:00
|
|
|
</List>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
export default SongList
|