From 3116e66c47d7344ae31295b307cae542338e27a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sat, 27 Apr 2024 11:28:30 +0200 Subject: [PATCH] Update meme voting --- assets/script.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/assets/script.js b/assets/script.js index 3cc421f..4ef8fd1 100644 --- a/assets/script.js +++ b/assets/script.js @@ -667,10 +667,35 @@ async function reloadMemeVotes(memeID) { } async function voteMeme(memeID, isUpvote){ - await doAction("/meme", { - action: "voteMeme", - meme_id: memeID, - is_upvote: isUpvote - }, "Meme bol upvotenutý", "Nastala chyba pri upvoteovaní meme-u", true); + let memeVoteUpvoteElement = document.getElementById(`meme_votes_upvote_${memeID}`); + let memeVoteDownvoteElement = document.getElementById(`meme_votes_downvote_${memeID}`); + let memeVoteDelete = false; + if(isUpvote) { + if(memeVoteUpvoteElement.classList.contains("ri-arrow-up-circle-fill")){ + deleteVoteMeme(memeID); + memeVoteDelete = true; + } + } + else { + if(memeVoteDownvoteElementElement.classList.contains("ri-arrow-up-circle-fill")){ + deleteVoteMeme(memeID); + memeVoteDelete = true; + } + } + if (!memeVoteDelete) { + await doAction("/meme", { + action: "voteMeme", + meme_id: memeID, + is_upvote: isUpvote + }, "Meme bol votovaný", "Nastala chyba pri votovaný", true); + } await reloadMemeVotes(memeID); +} + +async function deleteVoteMeme(memeId) { + await doAction("/meme", { + action: "deleteVoteMeme", + meme_id: memeId + }, "Hlas na meme bol zmazaný", "Nastala chyba pri mazaní hlasu na meme", true); + await reloadMemeVotes(memeId); } \ No newline at end of file