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