2020-05-29 08:33:50 -08:00
|
|
|
import React, { cloneElement, isValidElement, useState } from 'react'
|
2020-03-28 12:25:55 -08:00
|
|
|
import {
|
|
|
|
|
BooleanField,
|
|
|
|
|
Datagrid,
|
2020-05-29 08:33:50 -08:00
|
|
|
DatagridBody,
|
|
|
|
|
DatagridRow,
|
2020-03-28 12:25:55 -08:00
|
|
|
DateField,
|
2020-05-01 07:50:07 -08:00
|
|
|
NumberField,
|
2020-03-28 12:25:55 -08:00
|
|
|
Show,
|
|
|
|
|
SimpleShowLayout,
|
|
|
|
|
TextField,
|
|
|
|
|
} from 'react-admin'
|
2020-05-14 16:42:21 -08:00
|
|
|
import {
|
|
|
|
|
ArtistLinkField,
|
|
|
|
|
DurationField,
|
|
|
|
|
RangeField,
|
|
|
|
|
SimpleList,
|
|
|
|
|
} from '../common'
|
2020-03-28 12:25:55 -08:00
|
|
|
import { useMediaQuery } from '@material-ui/core'
|
2020-08-14 08:27:49 -08:00
|
|
|
import { AlbumContextMenu } from '../common'
|
2020-03-28 12:25:55 -08:00
|
|
|
|
|
|
|
|
const AlbumDetails = (props) => {
|
|
|
|
|
return (
|
|
|
|
|
<Show {...props} title=" ">
|
|
|
|
|
<SimpleShowLayout>
|
|
|
|
|
<TextField source="albumArtist" />
|
|
|
|
|
<TextField source="genre" />
|
|
|
|
|
<BooleanField source="compilation" />
|
|
|
|
|
<DateField source="updatedAt" showTime />
|
|
|
|
|
</SimpleShowLayout>
|
|
|
|
|
</Show>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 08:33:50 -08:00
|
|
|
const AlbumDatagridRow = ({ children, ...rest }) => {
|
|
|
|
|
const [visible, setVisible] = useState(false)
|
|
|
|
|
const childCount = React.Children.count(children)
|
|
|
|
|
return (
|
|
|
|
|
<DatagridRow
|
|
|
|
|
onMouseEnter={() => setVisible(true)}
|
|
|
|
|
onMouseLeave={() => setVisible(false)}
|
|
|
|
|
{...rest}
|
|
|
|
|
>
|
|
|
|
|
{React.Children.map(
|
|
|
|
|
children,
|
|
|
|
|
(child, index) =>
|
|
|
|
|
child &&
|
|
|
|
|
isValidElement(child) &&
|
|
|
|
|
(index < childCount - 1
|
|
|
|
|
? child
|
|
|
|
|
: cloneElement(child, {
|
|
|
|
|
visible,
|
|
|
|
|
}))
|
|
|
|
|
)}
|
|
|
|
|
</DatagridRow>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AlbumDatagridBody = (props) => (
|
|
|
|
|
<DatagridBody {...props} row={<AlbumDatagridRow />} />
|
|
|
|
|
)
|
|
|
|
|
const AlbumDatagrid = (props) => (
|
|
|
|
|
<Datagrid {...props} body={<AlbumDatagridBody />} />
|
|
|
|
|
)
|
|
|
|
|
|
2020-04-02 15:58:34 -08:00
|
|
|
const AlbumListView = ({ hasShow, hasEdit, hasList, ...rest }) => {
|
2020-03-28 12:25:55 -08:00
|
|
|
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
|
2020-05-01 07:50:07 -08:00
|
|
|
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
|
|
|
|
return isXsmall ? (
|
|
|
|
|
<SimpleList
|
|
|
|
|
primaryText={(r) => r.name}
|
|
|
|
|
secondaryText={(r) => r.albumArtist}
|
|
|
|
|
tertiaryText={(r) => (
|
|
|
|
|
<>
|
|
|
|
|
<RangeField record={r} source={'year'} sortBy={'maxYear'} />
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
linkType={'show'}
|
|
|
|
|
rightIcon={(r) => <AlbumContextMenu record={r} />}
|
|
|
|
|
{...rest}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2020-05-29 08:33:50 -08:00
|
|
|
<AlbumDatagrid expand={<AlbumDetails />} rowClick={'show'} {...rest}>
|
2020-04-24 13:37:28 -08:00
|
|
|
<TextField source="name" />
|
2020-06-22 04:56:55 -08:00
|
|
|
<ArtistLinkField source="artist" />
|
2020-06-09 03:45:23 -08:00
|
|
|
{isDesktop && <NumberField source="songCount" sortByOrder={'DESC'} />}
|
|
|
|
|
{isDesktop && <NumberField source="playCount" sortByOrder={'DESC'} />}
|
|
|
|
|
<RangeField source={'year'} sortBy={'maxYear'} sortByOrder={'DESC'} />
|
2020-03-28 12:25:55 -08:00
|
|
|
{isDesktop && <DurationField source="duration" />}
|
2020-05-01 07:27:09 -08:00
|
|
|
<AlbumContextMenu />
|
2020-05-29 08:33:50 -08:00
|
|
|
</AlbumDatagrid>
|
2020-03-28 12:25:55 -08:00
|
|
|
)
|
|
|
|
|
}
|
2020-05-01 07:50:07 -08:00
|
|
|
|
2020-03-28 12:25:55 -08:00
|
|
|
export default AlbumListView
|