Post to mastodon from the profile page for logged in users
This commit is contained in:
@@ -130,8 +130,17 @@ function renderFeed(items, showIdentity = true) {
|
||||
deleteButton.className = 'delete-button';
|
||||
deleteButton.textContent = 'Delete';
|
||||
deleteButton.addEventListener('click', () => deleteEntry(item, deleteButton));
|
||||
const mastodonButton = document.createElement('button');
|
||||
mastodonButton.type = 'button';
|
||||
mastodonButton.className = `mastodon-button${item.mastodon_posted ? ' posted' : ''}`;
|
||||
const mastodonLogo = document.createElement('img');
|
||||
mastodonLogo.src = '/static/mastodon.svg';
|
||||
mastodonLogo.alt = '';
|
||||
mastodonButton.append(mastodonLogo, document.createTextNode(item.mastodon_posted ? 'Post again' : 'Post to Mastodon'));
|
||||
mastodonButton.addEventListener('click', () => postToMastodon(item, mastodonButton));
|
||||
actions.append(editButton, deleteButton);
|
||||
article.appendChild(actions);
|
||||
article.appendChild(mastodonButton);
|
||||
}
|
||||
|
||||
if (showIdentity) {
|
||||
@@ -152,6 +161,19 @@ function renderFeed(items, showIdentity = true) {
|
||||
});
|
||||
}
|
||||
|
||||
async function postToMastodon(item, button) {
|
||||
button.disabled = true;
|
||||
const response = await fetch(`/api/links/${encodeURIComponent(item.id)}/mastodon`, {
|
||||
method: 'POST',
|
||||
headers: {Authorization: `Bearer ${accessToken}`},
|
||||
});
|
||||
if (response.ok) {
|
||||
await loadFeed();
|
||||
} else {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteEntry(item, button) {
|
||||
if (!window.confirm(`Delete this link?`)) return;
|
||||
button.disabled = true;
|
||||
|
||||
Reference in New Issue
Block a user