mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-02 00:21:14 +03:00
Allow toggling a playlist public from the Playlist list view. Closes #344
This commit is contained in:
parent
5e2d463129
commit
b4e06c416d
@ -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)
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user