Hi There,
It would be best if you could share your code with us, but if you can’t here is some code snippets from a project I have that uses Beautiful DND. I hope it help.
From a component that shows a list of videos that can be re-ordered. This is in a cell…
const UPDATE_PLAYLIST_ORDER = gql`
mutation UpdatePlayListOrder($id: Int!, $input: UpdatePlaylistOrderInput!) {
updatePlaylistOrder(id: $id, input: $input) {
id
title
videos {
id
order
video {
title
createdAt
playbackId
}
}
}
}
`
const [updatePlaylistOrder] = useMutation(UPDATE_PLAYLIST_ORDER, {
refetchQueries: ['FindPlaylistQuery'],
onCompleted: () => {
toast.success('Playlist order updated')
},
onError: (error) => {
toast.error(error.message)
},
})
const ondragEnd = (result) => {
const { destination, source } = result
if (!destination) {
return
}
if (
destination.droppableId === source.droppableId &&
destination.index === source.index
) {
return
}
const newVideos = Array.from(playlist.videos)
newVideos.splice(source.index, 1)
newVideos.splice(destination.index, 0, playlist.videos[source.index])
const videosForMutation = newVideos.map((video, index) => {
return {
id: video.id,
order: index,
}
})
updatePlaylistOrder({
variables: { id: playlist.id, input: { videos: videosForMutation } },
optimisticResponse: {
updatePlaylistOrder: {
id: playlist.id,
__typename: 'Playlist',
title: playlist.title,
videos: newVideos.map((video) => {
return {
id: video.id,
order: video.order,
video: {
title: video.video.title,
createdAt: video.video.createdAt,
playbackId: video.video.playbackId,
},
}
}),
},
},
})
}
<DragDropContext onDragEnd={ondragEnd}>
<Droppable droppableId={'1'}>
{(provided) => (
<VStack
divider={<Divider borderColor="#9A9A9A" my={3} />}
align="stretch"
width="100%"
{...provided.droppableProps}
ref={provided.innerRef}
>
{playlist.videos.map((video, index) => {
return (
<PlaylistVideo
key={video.id}
id={video.id}
playbackId={video.video.playbackId}
title={video.video.title}
createdAt={video.video.createdAt}
index={index}
playlistId={playlist.id}
/>
)
})}
{provided.placeholder}
</VStack>
)}
</Droppable>
</DragDropContext>
And then the individual component
const PlaylistVideo: React.FC<Props> = ({
playbackId,
title,
createdAt,
index,
id,
playlistId,
}) => {
return (
<Draggable draggableId={id.toString()} index={index}>
{(provided, snapshot) => {
return (
<Flex
{...provided.draggableProps}
{...provided.dragHandleProps}
ref={provided.innerRef}
bg={
snapshot.isDragging
? 'secondary.grey.main'
: 'secondary.grey.light'
}
px={4}
py={3}
>
<Box
mr={4}
flex={{ base: '0 0 200px', xl: '0 0 311px' }}
borderRadius={8}
overflow="hidden"
sx={{ aspectRatio: '16/9' }}
>
<MuxPlayer
style={{
maxWidth: '311px',
aspectRatio: '16/9',
width: '100%',
}}
streamType="on-demand"
playbackId={playbackId}
preferMse
metadata={{
video_id: playbackId,
video_title: `${title}`,
}}
playsInline
/>
</Box>
<Box flex="1 0 300px">
<Heading
as="h2"
fontWeight="semibold"
fontSize="lg"
color="primary.darkBlue.main"
>
{title}
</Heading>
<Text fontSize="md" color="#6C6B6B" mt={1}>
{new Intl.DateTimeFormat('en-GB', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(new Date(createdAt))}
</Text>
</Box>
<Flex
direction="column"
justifyContent="space-around"
alignItems="center"
>
<PlaylistDragIcon />
<DeletePlaylistVideo playlistId={playlistId} videoId={id} />
</Flex>
</Flex>
)
}}
</Draggable>
)
}