2020-05-05 14:28:55 -08:00
|
|
|
import React from 'react'
|
2020-05-08 06:47:06 -08:00
|
|
|
import {
|
2020-06-05 06:22:31 -08:00
|
|
|
Datagrid,
|
2020-05-08 06:47:06 -08:00
|
|
|
DateField,
|
2020-06-05 06:22:31 -08:00
|
|
|
EditButton,
|
2020-05-16 15:14:19 -08:00
|
|
|
Filter,
|
2020-06-05 06:22:31 -08:00
|
|
|
NumberField,
|
2020-05-16 15:14:19 -08:00
|
|
|
SearchInput,
|
2020-06-05 06:22:31 -08:00
|
|
|
TextField,
|
2020-06-08 14:39:31 -08:00
|
|
|
useUpdate,
|
|
|
|
|
useNotify,
|
2020-05-08 06:47:06 -08:00
|
|
|
} from 'react-admin'
|
2020-06-08 14:39:31 -08:00
|
|
|
import Switch from '@material-ui/core/Switch'
|
2020-05-11 17:27:00 -08:00
|
|
|
import { DurationField, List } from '../common'
|
2020-06-05 06:26:53 -08:00
|
|
|
import Writable, { isWritable } from '../common/Writable'
|
2020-05-05 14:28:55 -08:00
|
|
|
|
2020-05-16 15:14:19 -08:00
|
|
|
const PlaylistFilter = (props) => (
|
|
|
|
|
<Filter {...props}>
|
|
|
|
|
<SearchInput source="name" alwaysOn />
|
|
|
|
|
</Filter>
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-08 14:39:31 -08:00
|
|
|
const TogglePublicInput = ({ resource, record, source }) => {
|
|
|
|
|
const notify = useNotify()
|
|
|
|
|
const [togglePublic] = useUpdate(
|
|
|
|
|
resource,
|
|
|
|
|
record.id,
|
|
|
|
|
{
|
|
|
|
|
...record,
|
|
|
|
|
public: !record.public,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
undoable: false,
|
|
|
|
|
onFailure: (error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
notify('ra.page.error', 'warning')
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const handleClick = (e) => {
|
|
|
|
|
togglePublic()
|
|
|
|
|
e.stopPropagation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Switch checked={record[source]} onClick={handleClick} />
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 14:28:55 -08:00
|
|
|
const PlaylistList = (props) => (
|
2020-05-16 15:14:19 -08:00
|
|
|
<List {...props} exporter={false} filters={<PlaylistFilter />}>
|
2020-06-05 07:18:37 -08:00
|
|
|
<Datagrid rowClick="show" isRowSelectable={(r) => isWritable(r && r.owner)}>
|
2020-05-08 06:47:06 -08:00
|
|
|
<TextField source="name" />
|
|
|
|
|
<TextField source="owner" />
|
2020-05-10 15:59:47 -08:00
|
|
|
<NumberField source="songCount" />
|
2020-05-08 06:47:06 -08:00
|
|
|
<DurationField source="duration" />
|
|
|
|
|
<DateField source="updatedAt" />
|
2020-06-08 14:39:31 -08:00
|
|
|
<TogglePublicInput source="public" />
|
2020-06-05 06:22:31 -08:00
|
|
|
<Writable>
|
|
|
|
|
<EditButton />
|
|
|
|
|
</Writable>
|
|
|
|
|
/>
|
2020-05-05 14:28:55 -08:00
|
|
|
</Datagrid>
|
|
|
|
|
</List>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export default PlaylistList
|