quintodrome/ui/src/song/SongList.js

98 lines
2.7 KiB
JavaScript
Raw Normal View History

import React, { Fragment } from 'react'
import {
BooleanField,
Datagrid,
DateField,
Filter,
List,
NumberField,
SearchInput,
Show,
SimpleShowLayout,
TextField,
TextInput
} 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'
import AddToQueueButton from './AddToQueueButton'
import { PlayButton, SimpleList } from '../common'
2020-02-06 08:54:27 -09:00
import { useDispatch } from 'react-redux'
import { setTrack, addTrack } from '../player'
import AddIcon from '@material-ui/icons/Add'
const SongFilter = (props) => (
<Filter {...props}>
<SearchInput source="title" alwaysOn />
2020-01-22 07:22:35 -09:00
<TextInput source="album" />
<TextInput source="artist" />
</Filter>
)
const SongBulkActionButtons = (props) => (
<Fragment>
<AddToQueueButton {...props} />
</Fragment>
)
const SongDetails = (props) => {
return (
<Show {...props} title=" ">
<SimpleShowLayout>
<TextField source="path" />
2020-02-07 05:40:52 -09:00
<TextField source="albumArtist" />
<TextField source="genre" />
<BooleanField source="compilation" />
<BitrateField source="bitRate" />
<DateField source="updatedAt" showTime />
</SimpleShowLayout>
</Show>
)
}
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}
title={<Title subTitle={'Songs'} />}
sort={{ field: 'title', order: 'ASC' }}
exporter={false}
bulkActionButtons={<SongBulkActionButtons />}
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-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'} />}
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-02-06 08:54:27 -09:00
{isDesktop && <TextField source="album" />}
2020-02-05 14:16:00 -09:00
<TextField source="artist" />
2020-02-07 05:40:52 -09:00
{isDesktop && <NumberField source="trackNumber" />}
2020-02-06 08:54:27 -09:00
{isDesktop && <TextField source="year" />}
2020-02-07 05:40:52 -09:00
<DurationField source="duration" />
2020-02-05 14:16:00 -09:00
</Datagrid>
)}
</List>
)
}
export default SongList