63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
const blogID = document.getElementById("blogpost").dataset.id;
|
|
const titleInput = document.getElementById("title");
|
|
const descInput = document.getElementById("description");
|
|
const mdInput = document.getElementById("markdown");
|
|
const blueskyActorInput = document.getElementById("bluesky-actor");
|
|
const blueskyPostInput = document.getElementById("bluesky-post");
|
|
const visInput = document.getElementById("visibility");
|
|
const saveBtn = document.getElementById("save");
|
|
const deleteBtn = document.getElementById("delete");
|
|
|
|
saveBtn.addEventListener("click", () => {
|
|
fetch("/api/v1/blog/" + blogID, {
|
|
method: "PUT",
|
|
body: JSON.stringify({
|
|
title: titleInput.value,
|
|
description: descInput.value,
|
|
markdown: mdInput.value,
|
|
bluesky_actor: blueskyActorInput.value,
|
|
bluesky_post: blueskyPostInput.value,
|
|
visible: visInput.value === "true",
|
|
}),
|
|
headers: { "Content-Type": "application/json" }
|
|
}).then(res => {
|
|
if (!res.ok) {
|
|
res.text().then(error => {
|
|
console.error(error);
|
|
alert("Failed to update blog post: " + error);
|
|
});
|
|
return;
|
|
}
|
|
|
|
location = location;
|
|
});
|
|
});
|
|
|
|
deleteBtn.addEventListener("click", () => {
|
|
if (blogID != prompt(
|
|
"You are about to permanently delete " + blogID + ". " +
|
|
"This action is irreversible. " +
|
|
"Please enter \"" + blogID + "\" to continue.")) return;
|
|
fetch("/api/v1/blog/" + blogID, {
|
|
method: "DELETE",
|
|
}).then(res => {
|
|
if (!res.ok) {
|
|
res.text().then(error => {
|
|
console.error(error);
|
|
alert("Failed to delete blog post: " + error);
|
|
});
|
|
return;
|
|
}
|
|
|
|
location = "/admin";
|
|
});
|
|
});
|
|
|
|
[titleInput, descInput, mdInput, blueskyActorInput, blueskyPostInput, visInput].forEach(input => {
|
|
input.addEventListener("change", () => {
|
|
saveBtn.disabled = false;
|
|
});
|
|
input.addEventListener("keypress", () => {
|
|
saveBtn.disabled = false;
|
|
});
|
|
});
|