Skip to content

Commit

Permalink
reactively updates suscriptions if voting happened
Browse files Browse the repository at this point in the history
  • Loading branch information
santisiri committed Nov 28, 2017
1 parent 68aa81d commit da460e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion imports/api/contracts/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion imports/api/transactions/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion imports/ui/modules/Vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
};

Expand Down Expand Up @@ -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: {
Expand Down
19 changes: 11 additions & 8 deletions imports/ui/templates/components/decision/liquid/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand Down Expand Up @@ -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 = `<strong>${TAPi18n.__('none')}</strong> ${TAPi18n.__('placed-votes')}`;
Expand Down

0 comments on commit da460e6

Please sign in to comment.