commented new vote function

This commit is contained in:
2026-04-20 15:21:58 +02:00
parent 94d4308d3f
commit aec6a9bfb6

View File

@@ -553,7 +553,6 @@ function deleteContribution(contributionId) {
}); });
} }
// VOTE: Like or Dislike existing Contributions
// VOTE: Like or Dislike existing Contributions // VOTE: Like or Dislike existing Contributions
function voteContribution(contributionId, voteType) { function voteContribution(contributionId, voteType) {
if (!currentUser) { if (!currentUser) {
@@ -571,14 +570,14 @@ function voteContribution(contributionId, voteType) {
return; return;
} }
// Update local Vote State // Updates local Vote State
var likeBtn = document.getElementById('vote-like-' + contributionId); var likeBtn = document.getElementById('vote-like-' + contributionId);
var dislikeBtn = document.getElementById('vote-dislike-' + contributionId); var dislikeBtn = document.getElementById('vote-dislike-' + contributionId);
var likesSpan = document.getElementById('likes-' + contributionId); var likesSpan = document.getElementById('likes-' + contributionId);
var dislikesSpan = document.getElementById('dislikes-' + contributionId); var dislikesSpan = document.getElementById('dislikes-' + contributionId);
if (response.action === 'created') { if (response.action === 'created') {
// New Vote — highlight the Button, update Count // New Vote — Highlights Button and updates Count
userVotes[contributionId] = voteType; userVotes[contributionId] = voteType;
if (voteType === 'like') { if (voteType === 'like') {
likeBtn.classList.add('liked'); likeBtn.classList.add('liked');
@@ -588,7 +587,7 @@ function voteContribution(contributionId, voteType) {
dislikesSpan.textContent = parseInt(dislikesSpan.textContent) + 1; dislikesSpan.textContent = parseInt(dislikesSpan.textContent) + 1;
} }
} else if (response.action === 'removed') { } else if (response.action === 'removed') {
// Vote removed (Toggle off)remove Highlight, update Count // Vote removed — Removes Button Highlight and updates Count
delete userVotes[contributionId]; delete userVotes[contributionId];
if (voteType === 'like') { if (voteType === 'like') {
likeBtn.classList.remove('liked'); likeBtn.classList.remove('liked');
@@ -598,7 +597,7 @@ function voteContribution(contributionId, voteType) {
dislikesSpan.textContent = Math.max(0, parseInt(dislikesSpan.textContent) - 1); dislikesSpan.textContent = Math.max(0, parseInt(dislikesSpan.textContent) - 1);
} }
} else if (response.action === 'changed') { } else if (response.action === 'changed') {
// Vote changed (e.g. Like → Dislike)switch Highlights, update both Counts // Vote changed — Switches Highlights and updates both Counts
userVotes[contributionId] = voteType; userVotes[contributionId] = voteType;
if (voteType === 'like') { if (voteType === 'like') {
likeBtn.classList.add('liked'); likeBtn.classList.add('liked');