2020-02-04 05:26:54 -09:00
|
|
|
import React, { Fragment } from 'react'
|
2020-01-22 06:19:13 -09:00
|
|
|
import {
|
|
|
|
|
BooleanField,
|
|
|
|
|
Datagrid,
|
|
|
|
|
DateField,
|
|
|
|
|
Filter,
|
|
|
|
|
List,
|
|
|
|
|
NumberField,
|
|
|
|
|
SearchInput,
|
|
|
|
|
Show,
|
|
|
|
|
SimpleShowLayout,
|
2020-02-04 05:26:54 -09:00
|
|
|
TextField,
|
2020-02-05 14:16:00 -09:00
|
|
|
TextInput,
|
|
|
|
|
SimpleList
|
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-05 09:28:39 -09:00
|
|
|
import { BitrateField, DurationField, Pagination, Title } from '../common'
|
2020-02-04 05:26:54 -09:00
|
|
|
import AddToQueueButton from './AddToQueueButton'
|
|
|
|
|
import PlayButton from './PlayButton'
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
const SongFilter = (props) => (
|
|
|
|
|
<Filter {...props}>
|
|
|
|
|
<SearchInput source="title" alwaysOn />
|
2020-01-22 07:22:35 -09:00
|
|
|
<TextInput source="album" />
|
|
|
|
|
<TextInput source="artist" />
|
2020-01-22 06:19:13 -09:00
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const SongBulkActionButtons = (props) => (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<AddToQueueButton {...props} />
|
|
|
|
|
</Fragment>
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-22 06:19:13 -09:00
|
|
|
const SongDetails = (props) => {
|
|
|
|
|
return (
|
|
|
|
|
<Show {...props} title=" ">
|
|
|
|
|
<SimpleShowLayout>
|
|
|
|
|
<TextField source="path" />
|
|
|
|
|
<TextField label="Album Artist" source="albumArtist" />
|
|
|
|
|
<TextField source="genre" />
|
|
|
|
|
<BooleanField source="compilation" />
|
|
|
|
|
<BitrateField source="bitRate" />
|
|
|
|
|
<DateField source="updatedAt" showTime />
|
|
|
|
|
</SimpleShowLayout>
|
|
|
|
|
</Show>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 05:26:54 -09:00
|
|
|
const SongList = (props) => {
|
2020-02-05 14:16:00 -09:00
|
|
|
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
2020-02-04 05:26:54 -09:00
|
|
|
return (
|
|
|
|
|
<List
|
|
|
|
|
{...props}
|
|
|
|
|
title={<Title subTitle={'Songs'} />}
|
|
|
|
|
sort={{ field: 'title', order: 'ASC' }}
|
|
|
|
|
exporter={false}
|
|
|
|
|
bulkActionButtons={<SongBulkActionButtons />}
|
|
|
|
|
filters={<SongFilter />}
|
2020-02-05 09:28:39 -09:00
|
|
|
perPage={15}
|
|
|
|
|
pagination={<Pagination />}
|
2020-02-04 05:26:54 -09:00
|
|
|
>
|
2020-02-05 14:16:00 -09:00
|
|
|
{isXsmall ? (
|
|
|
|
|
<SimpleList
|
|
|
|
|
primaryText={(record) => (
|
|
|
|
|
<>
|
|
|
|
|
<PlayButton record={record} />
|
|
|
|
|
{record.title}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
secondaryText={(record) => record.artist}
|
|
|
|
|
tertiaryText={(record) => (
|
|
|
|
|
<DurationField record={record} source={'duration'} />
|
|
|
|
|
)}
|
|
|
|
|
linkType={false}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Datagrid expand={<SongDetails />}>
|
|
|
|
|
<PlayButton {...props} />
|
|
|
|
|
<TextField source="title" />
|
|
|
|
|
<TextField source="album" />
|
|
|
|
|
<TextField source="artist" />
|
|
|
|
|
<NumberField label="Track #" source="trackNumber" />
|
|
|
|
|
<NumberField label="Disc #" source="discNumber" />
|
|
|
|
|
<TextField source="year" />
|
|
|
|
|
<DurationField label="Time" source="duration" />
|
|
|
|
|
</Datagrid>
|
|
|
|
|
)}
|
2020-02-04 05:26:54 -09:00
|
|
|
</List>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-01-22 06:19:13 -09:00
|
|
|
|
|
|
|
|
export default SongList
|