eyecandy and delete
This commit is contained in:
+24
-2
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user