prevent lag effect when changing order
This commit is contained in:
parent
6697844239
commit
ca2262403b
@ -39,6 +39,7 @@ const Content = ({ form, playlistId }) => {
|
||||
};
|
||||
|
||||
const changePositionValue = (from, to) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const formFiles = form.values.files;
|
||||
let below_position = to === 0 ? 0 : formFiles[to].position;
|
||||
let above_position = formFiles[to].position;
|
||||
@ -56,17 +57,18 @@ const Content = ({ form, playlistId }) => {
|
||||
// sending modification to server
|
||||
API.playlistChangeOrder(playlistId, { file_id: formFiles[from].id, position: newPosition })
|
||||
.then((res) => {
|
||||
if (res.status !== 200) {
|
||||
if (res.status == 200) {
|
||||
form.values.files[from].position = newPosition;
|
||||
return true;
|
||||
resolve(true);
|
||||
} else {
|
||||
setNotification(true, `Error when changing order (${res.status})`);
|
||||
return false;
|
||||
resolve(false);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
setNotification(true, err.message);
|
||||
return false;
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -115,9 +117,10 @@ const Content = ({ form, playlistId }) => {
|
||||
<Box mx="auto">
|
||||
<DragDropContext
|
||||
onDragEnd={({ destination, source }) => {
|
||||
changePositionValue(source.index, destination.index).then((success) => {
|
||||
if (success) {
|
||||
form.reorderListItem('files', { from: source.index, to: destination.index });
|
||||
changePositionValue(source.index, destination.index).then((success) => {
|
||||
if (!success) {
|
||||
form.reorderListItem('files', { from: destination.index, to: source.index });
|
||||
}
|
||||
});
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user