Skip to content

Commit

Permalink
fix: 버그수정
Browse files Browse the repository at this point in the history
  • Loading branch information
in-jun committed Oct 4, 2024
1 parent e3c40d5 commit 8e45c6b
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
}
const activeClass = isActive ? (type === 'like' ? 'liked' : type === 'dislike' ? 'disliked' : 'active') : '';
return `
<button class="action-button ${activeClass}" onclick="handleAction('${type}', () => { ${onclick} })">
<button class="action-button ${activeClass}" onclick="handleAction('${type}', function() { ${onclick} })">
${getSvgIcon(type)}
${count !== '' ? `<span>${count}</span>` : ''}
</button>
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8e45c6b

Please sign in to comment.