Skip to content

Commit ae77e77

Browse files
committed
Fix playlist deletion
1 parent f3b8ac2 commit ae77e77

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

web/src/common/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export async function removePlaylist(name, onSuccess, onFailure) {
337337
headers: {
338338
'Authorization': `Bearer ${adminToken}`
339339
},
340-
body: JSON.stringify(name)
340+
body: data
341341
})
342342
.then(handleFetchResponse)
343343
.then(json => {

web/src/main/playlist.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export function spawnPlaylistNode(id, name, json, nodeId) {
77
let template = document.getElementById("template-playlist");
88
const node = template.content.cloneNode(true);
99

10+
node.querySelector(".playlist").id = `playlist-${id}`;
11+
1012
// Set click callbacks
1113
node.querySelector(".card-image").onclick = () => {
1214
window.location=window.location.origin + window.location.pathname + `?playlist=${id}`;
@@ -16,10 +18,10 @@ export function spawnPlaylistNode(id, name, json, nodeId) {
1618
if (json.musics.some(x => x.playlists.includes(id))) {
1719
if (confirm("This playlist contains songs, are you sure you want to delete it?"))
1820
{
19-
removePlaylist(id);
21+
removePlaylist(id, () => { document.getElementById(`playlist-${id}`).remove(); }, () => {});
2022
}
2123
} else {
22-
removePlaylist(id);
24+
removePlaylist(id, () => { document.getElementById(`playlist-${id}`).remove(); }, () => {});
2325
}
2426
}
2527

@@ -67,19 +69,22 @@ export function spawnNewPlaylistNode(nodeId, json) {
6769
const node = template.content.cloneNode(true);
6870

6971
node.querySelector(".card-content > p").innerHTML = `Create new playlist`;
70-
node.querySelector(".card-image").onclick = () => { createNewPlaylist(json); };
72+
node.querySelector(".card-image").onclick = () => { createNewPlaylist(nodeId, json); };
7173
node.querySelector(".card-image").classList.add("requires-admin");
7274
if (!isLoggedIn()) {
7375
node.querySelector(".card-image").classList.add("is-hidden");
7476
}
7577

78+
node.querySelector(".dropdown").remove();
79+
7680
document.getElementById(nodeId).appendChild(node);
7781
}
7882

79-
function createNewPlaylist(json)
83+
function createNewPlaylist(nodeId, json)
8084
{
8185
var playlistName = window.prompt("Enter new playlist name");
8286
if (playlistName) {
87+
document.getElementById(nodeId).innerHTML = "";
8388
createPlaylist(playlistName, () => {
8489
json.playlists[playlistName] = {
8590
name: playlistName,

0 commit comments

Comments
 (0)