diff --git a/index.html b/index.html index 3b0b6d2..f563403 100644 --- a/index.html +++ b/index.html @@ -269,7 +269,7 @@ } const activeClass = isActive ? (type === 'like' ? 'liked' : type === 'dislike' ? 'disliked' : 'active') : ''; return ` - + ${getSvgIcon(type)} ${count !== '' ? `${count}` : ''} @@ -307,8 +307,12 @@ button.classList.add('processing'); debounce(() => { - action() + Promise.resolve(action()) .then(() => getComments()) + .catch(error => { + console.error('Error:', error); + alert("An error occurred. Please try again."); + }) .finally(() => { pendingRequests[type] = false; button.classList.remove('processing'); @@ -389,29 +393,27 @@ } function deleteComment(commentId) { - if (pendingRequests['deleteComment']) return; - pendingRequests['deleteComment'] = true; - - fetch(`/api/user/${username}/comments`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ commentId: commentId }) - }) - .then(response => response.json()) - .then(data => { - if (data.error) { - alert("Error: " + data.error); - } else { - alert(data.message); - getComments(); - } - }) - .catch(error => { - console.error('Error:', error); + return new Promise((resolve, reject) => { + fetch(`/api/user/${username}/comments`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ commentId: commentId }) }) - .finally(() => { - pendingRequests['deleteComment'] = false; - }); + .then(response => response.json()) + .then(data => { + if (data.error) { + alert("Error: " + data.error); + reject(data.error); + } else { + alert(data.message); + resolve(data); + } + }) + .catch(error => { + console.error('Error:', error); + reject(error); + }); + }); } checkLoginStatus();