use postToast in betting so the js deducting coins only execute if responde code is < 300

pull/2/head
Aevann1 2022-11-21 03:00:10 +02:00
parent 1f234ef67d
commit 62ffe2d628
3 changed files with 20 additions and 15 deletions

View File

@ -110,17 +110,22 @@ function poll_vote_1(oid, parentid, kind) {
curr.value = full_oid
}
function bet_vote(oid) {
for(let el of document.getElementsByClassName('bet')) {
el.disabled = true;
}
for(let el of document.getElementsByClassName('cost')) {
el.classList.add('d-none')
}
var scoretext = document.getElementById('option-' + oid);
var score = Number(scoretext.textContent);
scoretext.textContent = score + 1;
post(`/vote/post/option/${oid}`);
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
function bet_vote(t, oid) {
postToast(t, `/vote/post/option/${oid}`,
{
},
() => {
for(let el of document.getElementsByClassName('bet')) {
el.disabled = true;
}
for(let el of document.getElementsByClassName('cost')) {
el.classList.add('d-none')
}
var scoretext = document.getElementById('option-' + oid);
var score = Number(scoretext.textContent);
scoretext.textContent = score + 1;
document.getElementById("user-coins-amount").innerText = parseInt(document.getElementById("user-coins-amount").innerText) - 200;
}
);
}

View File

@ -288,7 +288,7 @@ class Submission(Base):
for o in self.options:
if o.exclusive > 1:
body += f'''<div class="custom-control mt-2"><input name="option-{self.id}" autocomplete="off" class="custom-control-input bet" type="radio" id="{o.id}" onchange="bet_vote('{o.id}','{self.id}')"'''
body += f'''<div class="custom-control mt-2"><input name="option-{self.id}" autocomplete="off" class="custom-control-input bet" type="radio" id="{o.id}" onchange="bet_vote(this,'{o.id}')"'''
if o.voted(v): body += " checked "
if not (v and v.coins >= POLL_BET_COINS) or self.total_bet_voted(v): body += " disabled "

View File

@ -49,7 +49,7 @@ def vote_option(option_id, v):
elif existing and not option.exclusive:
g.db.delete(existing)
return "", 204
return {"message": "Bet successful!"}, 204
@app.get("/votes/post/option/<option_id>")
@auth_required