Allow toggling a playlist public from the Playlist list view. Closes #344

This commit is contained in:
Deluan 2020-06-08 18:39:31 -04:00
parent 5e2d463129
commit b4e06c416d
2 changed files with 37 additions and 5 deletions

View File

@ -87,9 +87,13 @@ func (r *playlistRepository) Put(p *model.Playlist) error {
return err
}
p.ID = id
err = r.updateTracks(id, tracks)
if err != nil {
return err
// Only update tracks if they are specified
if tracks != nil {
err = r.updateTracks(id, tracks)
if err != nil {
return err
}
}
return r.loadTracks(p)
}

View File

@ -1,6 +1,5 @@
import React from 'react'
import {
BooleanField,
Datagrid,
DateField,
EditButton,
@ -8,7 +7,10 @@ import {
NumberField,
SearchInput,
TextField,
useUpdate,
useNotify,
} from 'react-admin'
import Switch from '@material-ui/core/Switch'
import { DurationField, List } from '../common'
import Writable, { isWritable } from '../common/Writable'
@ -18,15 +20,41 @@ const PlaylistFilter = (props) => (
</Filter>
)
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} />
}
const PlaylistList = (props) => (
<List {...props} exporter={false} filters={<PlaylistFilter />}>
<Datagrid rowClick="show" isRowSelectable={(r) => isWritable(r && r.owner)}>
<TextField source="name" />
<TextField source="owner" />
<BooleanField source="public" />
<NumberField source="songCount" />
<DurationField source="duration" />
<DateField source="updatedAt" />
<TogglePublicInput source="public" />
<Writable>
<EditButton />
</Writable>