remove file from a playlist
This commit is contained in:
parent
4fc95a3b7f
commit
6697844239
@ -51,13 +51,31 @@ const Content = ({ form, playlistId }) => {
|
||||
above_position = formFiles[to + 1].position;
|
||||
}
|
||||
}
|
||||
let newPosition = (below_position + above_position) / 2
|
||||
form.values.files[from].position = newPosition;
|
||||
let newPosition = (below_position + above_position) / 2;
|
||||
|
||||
// sending modification to server
|
||||
API.playlistChangeOrder(playlistId, {file_id: formFiles[from].id, position: newPosition})
|
||||
API.playlistChangeOrder(playlistId, { file_id: formFiles[from].id, position: newPosition })
|
||||
.then((res) => {
|
||||
if (res.status !== 200) {
|
||||
form.values.files[from].position = newPosition;
|
||||
return true;
|
||||
} else {
|
||||
setNotification(true, `Error when changing order (${res.status})`);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
setNotification(true, err.message);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (index) => {
|
||||
API.playlistRemoveFile(playlistId, { file_id: form.values.files[index].id })
|
||||
.then((res) => {
|
||||
if (res.status == 200) {
|
||||
form.removeListItem('files', index);
|
||||
} else {
|
||||
setNotification(true, `Error when changing order (${res.status})`);
|
||||
}
|
||||
})
|
||||
@ -66,10 +84,6 @@ const Content = ({ form, playlistId }) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (index) => {
|
||||
form.removeListItem('files', index);
|
||||
};
|
||||
|
||||
const fields = form.values.files.map((_, index) => (
|
||||
<Draggable key={index} index={index} draggableId={index.toString()}>
|
||||
{(provided) => (
|
||||
@ -101,8 +115,11 @@ const Content = ({ form, playlistId }) => {
|
||||
<Box mx="auto">
|
||||
<DragDropContext
|
||||
onDragEnd={({ destination, source }) => {
|
||||
changePositionValue(source.index, destination.index);
|
||||
form.reorderListItem('files', { from: source.index, to: destination.index });
|
||||
changePositionValue(source.index, destination.index).then((success) => {
|
||||
if (success) {
|
||||
form.reorderListItem('files', { from: source.index, to: destination.index });
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
<StrictModeDroppable droppableId="dnd-list" direction="vertical">
|
||||
|
||||
@ -27,8 +27,10 @@ const API = {
|
||||
},
|
||||
playlistChangeOrder(playlistId, data) {
|
||||
return caller().post(`/playlist/${playlistId}/order`, data);
|
||||
|
||||
}
|
||||
},
|
||||
playlistRemoveFile(playlistId, data) {
|
||||
return caller().post(`/playlist/${playlistId}/remove_file`, data);
|
||||
},
|
||||
};
|
||||
|
||||
export default API;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user