Fix deleting template making a call on empty template list

This commit is contained in:
jude 2023-07-30 17:16:37 +01:00
parent 99eea16f62
commit b8707bbc9a

View File

@ -872,23 +872,25 @@ $loadTemplateBtn.addEventListener("click", (ev) => {
}); });
$deleteTemplateBtn.addEventListener("click", (ev) => { $deleteTemplateBtn.addEventListener("click", (ev) => {
fetch(`/dashboard/api/guild/${guildId()}/templates`, { if (parseInt($templateSelect.value) !== null) {
method: "DELETE", fetch(`/dashboard/api/guild/${guildId()}/templates`, {
headers: { method: "DELETE",
"Content-Type": "application/json", headers: {
}, "Content-Type": "application/json",
body: JSON.stringify({ id: parseInt($templateSelect.value) }), },
}) body: JSON.stringify({ id: parseInt($templateSelect.value) }),
.then((response) => response.json()) })
.then((data) => { .then((response) => response.json())
if (data.error) { .then((data) => {
show_error(data.error); if (data.error) {
} else { show_error(data.error);
$templateSelect } else {
.querySelector(`option[value="${$templateSelect.value}"]`) $templateSelect
.remove(); .querySelector(`option[value="${$templateSelect.value}"]`)
} .remove();
}); }
});
}
}); });
let $img; let $img;