From 650e93b9a29347dcb9ef1d5495bb93f6ff160b5c Mon Sep 17 00:00:00 2001 From: Tushar Karkera <104358692+TusharKarkera22@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:08:13 +0530 Subject: [PATCH 1/5] Voters list requires page reload #295 --- .../ballots/components/BallotListItem.vue | 17 +++++- src/pages/trails/ballots/view/BallotView.vue | 57 ++++++++++++------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/pages/trails/ballots/components/BallotListItem.vue b/src/pages/trails/ballots/components/BallotListItem.vue index 1df76679..f89ac41a 100644 --- a/src/pages/trails/ballots/components/BallotListItem.vue +++ b/src/pages/trails/ballots/components/BallotListItem.vue @@ -79,6 +79,14 @@ export default { 100; return this.trunc(total, 2); }, + updateVotedChipVisibility() { + this.$nextTick(() => { + const votedChip = this.$refs.votedChip; + if (votedChip) { + votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; + } + }); + }, async onCastVote({ options, option, ballotName }) { this.voting = true; await this.castVote({ @@ -109,9 +117,12 @@ div img(:src="`statics/app-icons/inactive-bgr-icon2.png`").bgr-icon2 div.column.items-start.absolute-top-left ballot-chip(:type="ballot.category", :isBallotOpened="isBallotOpened") - ballot-chip(:type="'voted'", - :isBallotOpened="isBallotOpened", - :class="userVotes[ballot.ballot_name] ? '' : 'hidden'") + ballot-chip( + :type="'voted'" + :isBallotOpened="isBallotOpened" + :class="userVotes[ballot.ballot_name] ? '' : 'hidden'" + v-if="isBallotOpened" + ) q-separator.card-separator-vertical(vertical inset) diff --git a/src/pages/trails/ballots/view/BallotView.vue b/src/pages/trails/ballots/view/BallotView.vue index 080fc707..28a4413b 100644 --- a/src/pages/trails/ballots/view/BallotView.vue +++ b/src/pages/trails/ballots/view/BallotView.vue @@ -35,6 +35,7 @@ export default { scrollPosition: null, notice: false, showDetails: false, + showVotedChip: false, }; }, async mounted() { @@ -268,6 +269,14 @@ export default { options: options || [option], }); this.voting = false; + console.log('vote',ballotName) + // Check if the voting was successful, then update voted chip visibility + if (this.userVotes[ballotName]) { + this.updateVotedChipVisibility(); + + + + } }, showAlert(message) { this.$q.notify({ @@ -279,13 +288,13 @@ export default { showNotification() { this.$q.notify({ icon: this.notifications[0].icon, - message: - this.notifications[0].status === 'success' - ? this.$t('notifications.trails.successSigning') - : this.$t('notifications.trails.errorSigning'), - color: - this.notifications[0].status === 'success' ? 'positive' : 'negative', + message:this.notifications[0].status === 'success'?this.$t('notifications.trails.successSigning'): this.$t('notifications.trails.errorSigning'), + color:this.notifications[0].status === 'success' ? 'positive' : 'negative', + }); + if (this.notifications[0].status === 'success') { + this.userVotes[this.ballot.ballot_name] = true; + } }, async showVoters() { this.showDetails = this.voters.length > 0; @@ -316,10 +325,12 @@ export default { if (this.isPositiveVotePower) { if (this.isUserRegisteredInTreasury) { register = false; - } else { + } + else { if (this.ballot.treasury.access === 'public') { register = true; - } else { + } + else { // redirect to treasuties page with filter this.$router.push({ path: '/trails/treasuries', @@ -328,15 +339,18 @@ export default { return; // Do not Cast Vote } } - } else { + } + else { if (this.isOfficialSymbol) { this.showAlert('pages.trails.ballots.stakeBeforeVotingLong'); - } else { + } + else { this.showAlert( - 'pages.trails.ballots.needPositiveVoteLong.' + - this.votingPowerComesFrom + 'pages.trails.ballots.needPositiveVoteLong.' + + this.votingPowerComesFrom ); } + return; } @@ -349,6 +363,11 @@ export default { await this.resetUserVotes(); this.showNotification(); + this.userVotes[this.ballot.ballot_name] = true; + }, + + updateVotedChipVisibility() { + this.showVotedChip = true; }, async cancel() { await this.cancelBallot(this.ballot); @@ -383,10 +402,10 @@ export default { shouldDisableCheckbox(key) { return ( !this.isAuthenticated || - !this.isBallotOpened(this.ballot) || - (this.votes.length === this.ballot.max_options && - !this.votes.includes(key)) - ); + !this.isBallotOpened(this.ballot) || + (this.votes.length === this.ballot.max_options && + !this.votes.includes(key)) + ); }, displayBallotSelectionText() { if (this.votes.length === 0) { @@ -407,8 +426,8 @@ export default { }, canUserVote() { this.userCanVote = - this.votes.length >= this.ballot.min_options && - this.votes.length <= this.ballot.max_options; + this.votes.length >= this.ballot.min_options && + this.votes.length <= this.ballot.max_options; return this.userCanVote; }, shouldDisableVoteButton() { @@ -485,7 +504,7 @@ export default { ballot-chip(:type="ballot.category", :isBallotOpened="isBallotOpened(ballot)") ballot-chip(:type="'voted'", :isBallotOpened="isBallotOpened(ballot)", - :class="userVotes[ballot.ballot_name] ? '' : 'hidden'") + :class="{ 'hidden': !userVotes[ballot.ballot_name] }") ballot-status( :ballot="ballot" :isBallotOpened="isBallotOpened(ballot)" From b100e9be27fa5ed32ae05580e45739178dbcd7e5 Mon Sep 17 00:00:00 2001 From: Tushar Karkera <104358692+TusharKarkera22@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:01:46 +0530 Subject: [PATCH 2/5] Fixed incorrect display & account list requiring page refresh --- src/pages/trails/ballots/view/BallotView.vue | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pages/trails/ballots/view/BallotView.vue b/src/pages/trails/ballots/view/BallotView.vue index 28a4413b..f2327437 100644 --- a/src/pages/trails/ballots/view/BallotView.vue +++ b/src/pages/trails/ballots/view/BallotView.vue @@ -269,13 +269,15 @@ export default { options: options || [option], }); this.voting = false; - console.log('vote',ballotName) // Check if the voting was successful, then update voted chip visibility if (this.userVotes[ballotName]) { this.updateVotedChipVisibility(); - - - + await this.fetchBallot(this.$route.params.id); + this.getLoggedUserVotes(this.$route.params.id); + await this.fetchVotesForBallot({ + name: this.ballot.ballot_name, + limit: this.ballot.total_voters, + }); } }, showAlert(message) { @@ -294,6 +296,7 @@ export default { }); if (this.notifications[0].status === 'success') { this.userVotes[this.ballot.ballot_name] = true; + this.updateVotedChipVisibility(); } }, async showVoters() { @@ -317,7 +320,7 @@ export default { if (!this.userVotes) return; if (!this.userVotes[ballot_name]) return; let votes = this.userVotes[ballot_name].weighted_votes.map((v) => v.key); - this.votes = this.votes.concat(votes); + this.votes = this.votes.concat(votes); }, async vote() { let register = false; @@ -363,11 +366,12 @@ export default { await this.resetUserVotes(); this.showNotification(); - this.userVotes[this.ballot.ballot_name] = true; + }, - - updateVotedChipVisibility() { + async updateVotedChipVisibility() { this.showVotedChip = true; + await this.fetchBallot(this.$route.params.id); + const vote = await this.fetchVotersForBallot(this.$route.params.id); }, async cancel() { await this.cancelBallot(this.ballot); From aeff6e68e61e5a3220b602b38be63824c32d0bf5 Mon Sep 17 00:00:00 2001 From: Tushar Karkera <104358692+TusharKarkera22@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:15:38 +0530 Subject: [PATCH 3/5] Fixed indentation --- .../ballots/components/BallotListItem.vue | 12 +++++----- src/pages/trails/ballots/view/BallotView.vue | 22 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/pages/trails/ballots/components/BallotListItem.vue b/src/pages/trails/ballots/components/BallotListItem.vue index f89ac41a..07f38ce1 100644 --- a/src/pages/trails/ballots/components/BallotListItem.vue +++ b/src/pages/trails/ballots/components/BallotListItem.vue @@ -80,12 +80,12 @@ export default { return this.trunc(total, 2); }, updateVotedChipVisibility() { - this.$nextTick(() => { - const votedChip = this.$refs.votedChip; - if (votedChip) { - votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; - } - }); + this.$nextTick(() => { + const votedChip = this.$refs.votedChip; + if (votedChip) { + votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; + } + }); }, async onCastVote({ options, option, ballotName }) { this.voting = true; diff --git a/src/pages/trails/ballots/view/BallotView.vue b/src/pages/trails/ballots/view/BallotView.vue index f2327437..7a083d05 100644 --- a/src/pages/trails/ballots/view/BallotView.vue +++ b/src/pages/trails/ballots/view/BallotView.vue @@ -277,7 +277,7 @@ export default { await this.fetchVotesForBallot({ name: this.ballot.ballot_name, limit: this.ballot.total_voters, - }); + }); } }, showAlert(message) { @@ -297,7 +297,7 @@ export default { if (this.notifications[0].status === 'success') { this.userVotes[this.ballot.ballot_name] = true; this.updateVotedChipVisibility(); - } + } }, async showVoters() { this.showDetails = this.voters.length > 0; @@ -320,7 +320,7 @@ export default { if (!this.userVotes) return; if (!this.userVotes[ballot_name]) return; let votes = this.userVotes[ballot_name].weighted_votes.map((v) => v.key); - this.votes = this.votes.concat(votes); + this.votes = this.votes.concat(votes); }, async vote() { let register = false; @@ -328,11 +328,11 @@ export default { if (this.isPositiveVotePower) { if (this.isUserRegisteredInTreasury) { register = false; - } + } else { if (this.ballot.treasury.access === 'public') { register = true; - } + } else { // redirect to treasuties page with filter this.$router.push({ @@ -342,14 +342,14 @@ export default { return; // Do not Cast Vote } } - } + } else { if (this.isOfficialSymbol) { this.showAlert('pages.trails.ballots.stakeBeforeVotingLong'); - } + } else { this.showAlert( - 'pages.trails.ballots.needPositiveVoteLong.' + + 'pages.trails.ballots.needPositiveVoteLong.' + this.votingPowerComesFrom ); } @@ -370,8 +370,8 @@ export default { }, async updateVotedChipVisibility() { this.showVotedChip = true; - await this.fetchBallot(this.$route.params.id); - const vote = await this.fetchVotersForBallot(this.$route.params.id); + await this.fetchBallot(this.$route.params.id); + await this.fetchVotersForBallot(this.$route.params.id); }, async cancel() { await this.cancelBallot(this.ballot); @@ -409,7 +409,7 @@ export default { !this.isBallotOpened(this.ballot) || (this.votes.length === this.ballot.max_options && !this.votes.includes(key)) - ); + ); }, displayBallotSelectionText() { if (this.votes.length === 0) { From cd6110bbecf7214eec7e76b71c7da9bc00b45715 Mon Sep 17 00:00:00 2001 From: Tushar Karkera <104358692+TusharKarkera22@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:19:00 +0530 Subject: [PATCH 4/5] Fixed BallotListItem indentation --- src/pages/trails/ballots/components/BallotListItem.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/trails/ballots/components/BallotListItem.vue b/src/pages/trails/ballots/components/BallotListItem.vue index 07f38ce1..c29d6b61 100644 --- a/src/pages/trails/ballots/components/BallotListItem.vue +++ b/src/pages/trails/ballots/components/BallotListItem.vue @@ -81,10 +81,10 @@ export default { }, updateVotedChipVisibility() { this.$nextTick(() => { - const votedChip = this.$refs.votedChip; - if (votedChip) { - votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; - } + const votedChip = this.$refs.votedChip; + if (votedChip) { + votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; + } }); }, async onCastVote({ options, option, ballotName }) { From 012429d714f94de78f200277aff983f25d353c0c Mon Sep 17 00:00:00 2001 From: Tushar Karkera <104358692+TusharKarkera22@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:22:06 +0530 Subject: [PATCH 5/5] Update BallotListItem --- src/pages/trails/ballots/components/BallotListItem.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/trails/ballots/components/BallotListItem.vue b/src/pages/trails/ballots/components/BallotListItem.vue index c29d6b61..dab14149 100644 --- a/src/pages/trails/ballots/components/BallotListItem.vue +++ b/src/pages/trails/ballots/components/BallotListItem.vue @@ -83,7 +83,7 @@ export default { this.$nextTick(() => { const votedChip = this.$refs.votedChip; if (votedChip) { - votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; + votedChip.style.display = this.userVotes[this.ballot.ballot_name] ? 'flex' : 'none'; } }); },