Add Auto-Import toggle switch to playlists list view.

This commit is contained in:
Caio Cotts 2024-06-07 21:24:11 -04:00 committed by Caio Cotts
parent 0de5f594fe
commit 9b4abd9e5a

View File

@ -82,6 +82,39 @@ const TogglePublicInput = ({ resource, source }) => {
)
}
const ToggleAutoImport = ({ resource, source }) => {
const record = useRecordContext()
console.log(record)
const notify = useNotify()
const [ToggleAutoImport] = useUpdate(
resource,
record.id,
{
...record,
sync: !record.sync,
},
{
undoable: false,
onFailure: (error) => {
console.log(error)
notify('ra.page.error', 'warning')
},
},
)
const handleClick = (e) => {
ToggleAutoImport()
e.stopPropagation()
}
return record.path ? (
<Switch
checked={record[source]}
onClick={handleClick}
disabled={!isWritable(record.ownerId)}
/>
) : null
}
const PlaylistListBulkActions = (props) => (
<>
<ChangePublicStatusButton public={true} {...props} />
@ -107,6 +140,7 @@ const PlaylistList = (props) => {
<TogglePublicInput source="public" sortByOrder={'DESC'} />
),
comment: <TextField source="comment" />,
sync: <ToggleAutoImport source="sync" sortByOrder={'DESC'} />,
}),
[isDesktop, isXsmall],
)