Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voters list requires page reload #295 #333

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/pages/trails/ballots/components/BallotListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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)

Expand Down
57 changes: 40 additions & 17 deletions src/pages/trails/ballots/view/BallotView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
scrollPosition: null,
notice: false,
showDetails: false,
showVotedChip: false,
};
},
async mounted() {
Expand Down Expand Up @@ -268,6 +269,16 @@
options: options || [option],
});
this.voting = false;
// 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) {
this.$q.notify({
Expand All @@ -279,13 +290,14 @@
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'),

Check warning on line 293 in src/pages/trails/ballots/view/BallotView.vue

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 160. Maximum allowed is 120
color:this.notifications[0].status === 'success' ? 'positive' : 'negative',

});
if (this.notifications[0].status === 'success') {
this.userVotes[this.ballot.ballot_name] = true;
this.updateVotedChipVisibility();
}
},
async showVoters() {
this.showDetails = this.voters.length > 0;
Expand Down Expand Up @@ -316,10 +328,12 @@
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',
Expand All @@ -328,15 +342,18 @@
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
this.votingPowerComesFrom
);
}

return;
}

Expand All @@ -349,6 +366,12 @@
await this.resetUserVotes();

this.showNotification();

},
async updateVotedChipVisibility() {
this.showVotedChip = true;
await this.fetchBallot(this.$route.params.id);
await this.fetchVotersForBallot(this.$route.params.id);
},
async cancel() {
await this.cancelBallot(this.ballot);
Expand Down Expand Up @@ -383,9 +406,9 @@
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() {
Expand All @@ -407,8 +430,8 @@
},
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() {
Expand Down Expand Up @@ -485,7 +508,7 @@
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)"
Expand Down
Loading