Use `refetch` when changing the playlist (as opposed to a full `refresh`)

This commit is contained in:
Deluan 2021-10-27 20:53:58 -04:00
parent 85d48478e8
commit cca32360db
1 changed files with 7 additions and 10 deletions

View File

@ -4,7 +4,6 @@ import {
ListToolbar,
TextField,
NumberField,
useRefresh,
useDataProvider,
useNotify,
useVersion,
@ -85,12 +84,11 @@ const ReorderableList = ({ readOnly, children, ...rest }) => {
const PlaylistSongs = ({ playlistId, readOnly, actions, ...props }) => {
const listContext = useListContext()
const { data, ids, onUnselectItems } = listContext
const { data, ids, selectedIds, onUnselectItems, refetch } = listContext
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
const classes = useStyles({ isDesktop })
const dispatch = useDispatch()
const dataProvider = useDataProvider()
const refresh = useRefresh()
const notify = useNotify()
const version = useVersion()
useResourceRefresh('song', 'playlist')
@ -98,10 +96,10 @@ const PlaylistSongs = ({ playlistId, readOnly, actions, ...props }) => {
const onAddToPlaylist = useCallback(
(pls) => {
if (pls.id === playlistId) {
refresh()
refetch()
}
},
[playlistId, refresh]
[playlistId, refetch]
)
const reorder = useCallback(
@ -113,13 +111,13 @@ const PlaylistSongs = ({ playlistId, readOnly, actions, ...props }) => {
filter: { playlist_id: playlistId },
})
.then(() => {
refresh()
refetch()
})
.catch(() => {
notify('ra.page.error', 'warning')
})
},
[dataProvider, notify, refresh]
[dataProvider, notify, refetch]
)
const handleDragEnd = useCallback(
@ -169,16 +167,15 @@ const PlaylistSongs = ({ playlistId, readOnly, actions, ...props }) => {
classes={{ toolbar: classes.toolbar }}
filters={props.filters}
actions={actions}
{...listContext}
/>
<div className={classes.main}>
<Card
className={clsx(classes.content, {
[classes.bulkActionsDisplayed]: listContext.selectedIds.length > 0,
[classes.bulkActionsDisplayed]: selectedIds.length > 0,
})}
key={version}
>
<BulkActionsToolbar {...listContext}>
<BulkActionsToolbar>
<PlaylistSongBulkActions
playlistId={playlistId}
onUnselectItems={onUnselectItems}