remove file from a playlist

This commit is contained in:
grimhilt 2023-07-31 01:48:22 +02:00
parent 4fc95a3b7f
commit 6697844239
2 changed files with 30 additions and 11 deletions

View File

@ -51,13 +51,31 @@ const Content = ({ form, playlistId }) => {
above_position = formFiles[to + 1].position; above_position = formFiles[to + 1].position;
} }
} }
let newPosition = (below_position + above_position) / 2 let newPosition = (below_position + above_position) / 2;
form.values.files[from].position = newPosition;
// sending modification to server // 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) => { .then((res) => {
if (res.status !== 200) { 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})`); 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) => ( const fields = form.values.files.map((_, index) => (
<Draggable key={index} index={index} draggableId={index.toString()}> <Draggable key={index} index={index} draggableId={index.toString()}>
{(provided) => ( {(provided) => (
@ -101,8 +115,11 @@ const Content = ({ form, playlistId }) => {
<Box mx="auto"> <Box mx="auto">
<DragDropContext <DragDropContext
onDragEnd={({ destination, source }) => { onDragEnd={({ destination, source }) => {
changePositionValue(source.index, destination.index); changePositionValue(source.index, destination.index).then((success) => {
if (success) {
form.reorderListItem('files', { from: source.index, to: destination.index }); form.reorderListItem('files', { from: source.index, to: destination.index });
}
});
}} }}
> >
<StrictModeDroppable droppableId="dnd-list" direction="vertical"> <StrictModeDroppable droppableId="dnd-list" direction="vertical">

View File

@ -27,8 +27,10 @@ const API = {
}, },
playlistChangeOrder(playlistId, data) { playlistChangeOrder(playlistId, data) {
return caller().post(`/playlist/${playlistId}/order`, data); return caller().post(`/playlist/${playlistId}/order`, data);
},
} playlistRemoveFile(playlistId, data) {
return caller().post(`/playlist/${playlistId}/remove_file`, data);
},
}; };
export default API; export default API;