early admin edit blog page
This commit is contained in:
parent
65366032fd
commit
82fd17c836
7 changed files with 297 additions and 15 deletions
100
admin/static/edit-blog.css
Normal file
100
admin/static/edit-blog.css
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
input[type="text"] {
|
||||
padding: .3em .5em;
|
||||
font-size: inherit;
|
||||
font-family: inherit;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
outline: none;
|
||||
color: inherit;
|
||||
background-color: var(--bg-1);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
#blogpost {
|
||||
margin-bottom: 1em;
|
||||
padding: 1.5em;
|
||||
|
||||
border-radius: 8px;
|
||||
background-color: var(--bg-2);
|
||||
box-shadow: var(--shadow-lg);
|
||||
|
||||
transition: background .1s ease-out, color .1s ease-out;
|
||||
}
|
||||
|
||||
#blogpost label {
|
||||
margin: 1.2em 0 .2em .1em;
|
||||
display: block;
|
||||
font-size: .8em;
|
||||
text-transform: uppercase;
|
||||
font-weight: 600;
|
||||
}
|
||||
#blogpost label:first-of-type {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#blogpost h2 {
|
||||
margin: 0;
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
#blogpost #title {
|
||||
width: 100%;
|
||||
margin: 0 -.2em;
|
||||
padding: 0 .2em;
|
||||
resize: none;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
font-weight: bold;
|
||||
border-radius: 4px;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
color: var(--fg-3);
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
transition: background .1s ease-out, border-color .1s ease-out;
|
||||
|
||||
/*position: relative; outline: none;*/
|
||||
white-space: pre-wrap; overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
#blogpost #title:hover {
|
||||
background-color: var(--bg-3);
|
||||
border-color: var(--fg-0);
|
||||
}
|
||||
|
||||
#blogpost #title:active,
|
||||
#blogpost #title:focus {
|
||||
background-color: var(--bg-3);
|
||||
}
|
||||
|
||||
#blogpost textarea {
|
||||
width: calc(100% - 2em);
|
||||
margin: 0;
|
||||
padding: 1em;
|
||||
display: block;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: var(--bg-1);
|
||||
color: var(--fg-3);
|
||||
box-shadow: var(--shadow-md);
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#blogpost #description {
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
#blogpost select {
|
||||
padding: .5em .8em;
|
||||
font-size: inherit;
|
||||
border: none;
|
||||
border-radius: 10em;
|
||||
color: var(--fg-3);
|
||||
background-color: var(--bg-1);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
#blogpost .blog-actions {
|
||||
margin-top: 1em;
|
||||
}
|
||||
63
admin/static/edit-blog.js
Normal file
63
admin/static/edit-blog.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
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;
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue