Skip to content

Commit

Permalink
좋아요 및 싫어요 기능에서 중복 요청 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
in-jun committed May 30, 2024
1 parent 1af9b33 commit e36ccbf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
const commentsContainer = document.getElementById("commentsContainer");
const commentInput = document.getElementById("commentInput");
let loggedInUser = null;
let processingRequest = false;

function updateUI(loggedIn) {
authButton.style.display = loggedIn ? "none" : "block";
Expand Down Expand Up @@ -273,17 +274,23 @@
}

async function likeComment(commentId, isDisliked) {
if (processingRequest) return;
processingRequest = true;
if (isDisliked) {
await removeDislikeComment(commentId);
}
await sendLikeRequest(commentId);
processingRequest = false;
}

async function dislikeComment(commentId, isLiked) {
if (processingRequest) return;
processingRequest = true;
if (isLiked) {
await removelikeComment(commentId);
}
await sendDislikeRequest(commentId);
processingRequest = false;
}

async function sendLikeRequest(commentId) {
Expand Down Expand Up @@ -319,6 +326,8 @@
}

async function removelikeComment(commentId) {
if (processingRequest) return;
processingRequest = true;
try {
const response = await fetch(`/api/like/remove-like/${commentId}`, {
method: 'POST',
Expand All @@ -332,9 +341,12 @@
} catch (error) {
console.error('Error:', error);
}
processingRequest = false;
}

async function removeDislikeComment(commentId) {
if (processingRequest) return;
processingRequest = true;
try {
const response = await fetch(`/api/like/remove-dislike/${commentId}`, {
method: 'POST',
Expand All @@ -348,9 +360,12 @@
} catch (error) {
console.error('Error:', error);
}
processingRequest = false;
}

async function OwnerlikeComment(commentId) {
if (processingRequest) return;
processingRequest = true;
try {
const response = await fetch(`/api/like/owner-like/${commentId}`, {
method: 'POST',
Expand All @@ -364,9 +379,12 @@
} catch (error) {
console.error('Error:', error);
}
processingRequest = false;
}

async function removeOwnerLikeComment(commentId) {
if (processingRequest) return;
processingRequest = true;
try {
const response = await fetch(`/api/like/owner-remove-like/${commentId}`, {
method: 'POST',
Expand All @@ -380,6 +398,7 @@
} catch (error) {
console.error('Error:', error);
}
processingRequest = false;
}

checkLoginStatus();
Expand Down

0 comments on commit e36ccbf

Please sign in to comment.