quintodrome/ui/src/song/SongList.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react'
import {
Datagrid,
Filter,
2020-03-30 15:34:00 -08:00
FunctionField,
NumberField,
SearchInput,
2020-04-16 06:26:24 -08:00
TextField,
} from 'react-admin'
2020-02-05 14:16:00 -09:00
import { useMediaQuery } from '@material-ui/core'
2020-05-15 06:20:11 -08:00
import { DurationField, SimpleList, List, SongDetails } from '../common'
2020-02-06 08:54:27 -09:00
import { useDispatch } from 'react-redux'
2020-05-01 06:22:24 -08:00
import { setTrack } from '../audioplayer'
import { SongBulkActions } from './SongBulkActions'
2020-03-30 15:34:00 -08:00
import { AlbumLinkField } from './AlbumLinkField'
2020-05-01 06:22:24 -08:00
import { SongContextMenu } from './SongContextMenu'
const SongFilter = (props) => (
<Filter {...props}>
<SearchInput source="title" alwaysOn />
</Filter>
)
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'))
return (
<List
{...props}
sort={{ field: 'title', order: 'ASC' }}
exporter={false}
bulkActionButtons={<SongBulkActions />}
filters={<SongFilter />}
2020-02-06 08:54:27 -09:00
perPage={isXsmall ? 50 : 15}
>
2020-02-05 14:16:00 -09:00
{isXsmall ? (
<SimpleList
2020-05-01 06:22:24 -08:00
primaryText={(r) => r.title}
secondaryText={(r) => r.artist}
tertiaryText={(r) => (
2020-02-05 14:16:00 -09:00
<>
2020-05-01 06:22:24 -08:00
<DurationField record={r} source={'duration'} />
&nbsp;&nbsp;&nbsp;
2020-02-05 14:16:00 -09:00
</>
)}
linkType={(id, basePath, record) => dispatch(setTrack(record))}
2020-05-01 06:22:24 -08:00
rightIcon={(r) => <SongContextMenu record={r} />}
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" />}
{isDesktop && <NumberField source="playCount" />}
{isDesktop && (
<FunctionField source="year" render={(r) => r.year || ''} />
)}
2020-02-07 05:40:52 -09:00
<DurationField source="duration" />
2020-05-01 06:22:24 -08:00
<SongContextMenu />
2020-02-05 14:16:00 -09:00
</Datagrid>
)}
</List>
)
}
export default SongList