eyecandy and delete

This commit is contained in:
2026-08-26 10:04:23 +02:00
parent 2e5610555e
commit 9deb28330a
9 changed files with 92 additions and 7 deletions
+24 -2
View File
@@ -117,13 +117,21 @@ function renderFeed(items, showIdentity = true) {
meta.className = 'meta';
meta.textContent = formatDate(item.created_at);
if (item.is_owner) {
if (item.is_owner && !showIdentity) {
const actions = document.createElement('div');
actions.className = 'entry-actions';
const editButton = document.createElement('button');
editButton.type = 'button';
editButton.className = 'edit-button';
editButton.textContent = 'Edit';
editButton.addEventListener('click', () => showEditForm(article, item));
article.appendChild(editButton);
const deleteButton = document.createElement('button');
deleteButton.type = 'button';
deleteButton.className = 'delete-button';
deleteButton.textContent = 'Delete';
deleteButton.addEventListener('click', () => deleteEntry(item, deleteButton));
actions.append(editButton, deleteButton);
article.appendChild(actions);
}
if (showIdentity) {
@@ -144,6 +152,20 @@ function renderFeed(items, showIdentity = true) {
});
}
async function deleteEntry(item, button) {
if (!window.confirm(`Delete this link?`)) return;
button.disabled = true;
const response = await fetch(`/api/links/${encodeURIComponent(item.id)}`, {
method: 'DELETE',
headers: {Authorization: `Bearer ${accessToken}`},
});
if (response.ok) {
await loadFeed();
} else {
button.disabled = false;
}
}
function showEditForm(article, item) {
if (article.querySelector('.edit-form')) return;
const form = document.createElement('form');