Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanthapa01 committed Feb 3, 2024
1 parent 81ba793 commit 6faaffa
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,39 +147,58 @@ async function submit() {
return;
}

// If not already liked, proceed with the like
set(userRef, {
Name: user.value,
Instagram: insta.value,
liked: true, // Mark the user as liked
liked: true,
isSpecial: false
})
.then(() => {
msg.innerText = `Thanks for the like! ${user.value}😍 `;
heart.style.opacity = '1';

// Increment the individual user like count
get(likeCountRef).then(snapshot => {
})
.then(() => {
console.log("User data updated successfully");
msg.innerText = `Thanks for the like! ${user.value}😍 `;
heart.style.opacity = '1';

// Increment the individual user like count
get(likeCountRef)
.then(snapshot => {
const currentLikeCount = snapshot.val() || 0;
set(likeCountRef, currentLikeCount + 1);
});

// Increment the total like count
get(ref(db, 'posts/totalLikes')).then(snapshot => {
})
.catch(error => {
console.error("Error updating individual like count:", error);
});

// Increment the total like count
get(ref(db, 'posts/totalLikes'))
.then(snapshot => {
const currentTotalLikeCount = snapshot.val() || 0;
set(ref(db, 'posts/totalLikes'), currentTotalLikeCount + 1);
});

// Disable the form after a successful like
disableForm();
})
.catch(error => {
alert(error);
console.error("Error updating total like count:", error);
});

// Disable the form after a successful like
disableForm();
})
.catch(error => {
console.error("Error updating user data:", error);
alert("An error occurred. Please try again later.");
});





});

}
// ...






// Function to disable the form elements
function disableForm() {
user.disabled = true;
Expand Down

0 comments on commit 6faaffa

Please sign in to comment.