From da460e6edfcb8b484ce6635466c13fc1963eabb7 Mon Sep 17 00:00:00 2001 From: Santiago Siri Date: Tue, 28 Nov 2017 16:21:32 -0500 Subject: [PATCH] reactively updates suscriptions if voting happened --- imports/api/contracts/server/publications.js | 2 +- imports/api/transactions/transaction.js | 2 +- imports/ui/modules/Vote.js | 3 ++- .../components/decision/liquid/liquid.js | 19 +++++++++++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/imports/api/contracts/server/publications.js b/imports/api/contracts/server/publications.js index 76a1571b4..ac7887e57 100644 --- a/imports/api/contracts/server/publications.js +++ b/imports/api/contracts/server/publications.js @@ -20,6 +20,6 @@ Meteor.publish('singleContract', (terms) => { check(terms, Object); const parameters = query(terms); - console.log(`[publish=singleVote] [user=${Meteor.user().username}] [contract=${terms.contractId}]`); + console.log(`[publish=singleContract] [user=${Meteor.user().username}] [contract=${terms.contractId}]`); return Contracts.find(parameters.find, parameters.options); }); diff --git a/imports/api/transactions/transaction.js b/imports/api/transactions/transaction.js index d252c815a..8987144d4 100644 --- a/imports/api/transactions/transaction.js +++ b/imports/api/transactions/transaction.js @@ -378,7 +378,7 @@ const _transact = (senderId, receiverId, votes, settings, callback) => { defaultSettings = { currency: 'VOTES', kind: 'VOTE', - contractId: false, // _getContractId(senderId, receiverId, settings.kind), + contractId: false, }; if (settings === undefined) { diff --git a/imports/ui/modules/Vote.js b/imports/ui/modules/Vote.js index 5056c5ac1..364def4e0 100644 --- a/imports/ui/modules/Vote.js +++ b/imports/ui/modules/Vote.js @@ -355,6 +355,7 @@ export class Vote { Session.set('dragging', false); const newWallet = new Vote(Meteor.users.findOne({ _id: this.userId }).profile.wallet, Session.get(this.voteId).targetId, this.voteId); Session.set(this.voteId, newWallet); + console.log(`setting new vote status for ${this.voteId}`); } }; @@ -403,7 +404,7 @@ export class Vote { actionLabel = TAPi18n.__('vote'); boolProfile = false; showBallot = true; - finalBallot = purgeBallot(getBallot(this.targetId)); // purgeBallot(Session.get('candidateBallot')); + finalBallot = purgeBallot(getBallot(this.targetId)); dictionary = 'votes'; settings = { condition: { diff --git a/imports/ui/templates/components/decision/liquid/liquid.js b/imports/ui/templates/components/decision/liquid/liquid.js index 976314ba5..f61dfcadb 100644 --- a/imports/ui/templates/components/decision/liquid/liquid.js +++ b/imports/ui/templates/components/decision/liquid/liquid.js @@ -170,15 +170,17 @@ Template.liquid.onCreated(function () { const instance = this; instance.autorun(function () { - const subscription = instance.subscribe('transaction', { view: 'singleVote', contractId: instance.data.targetId }); - if (subscription.ready()) { - wallet = new Vote(instance.data.wallet, instance.data.targetId, instance.data._id); - if (wallet.voteType === 'DELEGATION') { - instance.rightToVote.set(getRightToVote(wallet.delegationContract)); - instance.contract.set(wallet.delegationContract); + if (!Session.get('dragging')) { + const subscription = instance.subscribe('transaction', { view: 'singleVote', contractId: instance.data.targetId, sessionId: Session.get(instance.data._id) }); + if (subscription.ready()) { + wallet = new Vote(instance.data.wallet, instance.data.targetId, instance.data._id); + if (wallet.voteType === 'DELEGATION') { + instance.rightToVote.set(getRightToVote(wallet.delegationContract)); + instance.contract.set(wallet.delegationContract); + } + Session.set(instance.data._id, wallet); + instance.ready.set(true); } - Session.set(instance.data._id, wallet); - instance.ready.set(true); } }); }); @@ -385,6 +387,7 @@ Template.capital.helpers({ case 'placed': default: placed = Session.get(this._id).placed; + console.log(placed); percentagePlaced = getPercentage(parseInt(placed - inBallot, 10), this._id); if (placed === 0 || percentagePlaced === 0) { label = `${TAPi18n.__('none')} ${TAPi18n.__('placed-votes')}`;