From 926bd7c2fec335c236e6ca0de69fc214fc736019 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Fri, 14 Jul 2023 15:51:13 -0400 Subject: [PATCH] Add 'hide votes' option until poll has ended Fixes #2 --- js/src/forum/components/CreatePollModal.js | 14 ++++++++++++++ js/src/forum/components/EditPollModal.js | 2 ++ js/src/forum/components/PostPoll.js | 3 ++- js/src/forum/models/Poll.js | 2 ++ resources/less/forum.less | 8 ++++++++ resources/locale/en.yml | 1 + src/Access/PollPolicy.php | 4 ++++ src/Commands/EditPollHandler.php | 11 ++++------- src/Poll.php | 6 ++++++ 9 files changed, 43 insertions(+), 8 deletions(-) diff --git a/js/src/forum/components/CreatePollModal.js b/js/src/forum/components/CreatePollModal.js index bd3288fc..30d265a1 100755 --- a/js/src/forum/components/CreatePollModal.js +++ b/js/src/forum/components/CreatePollModal.js @@ -19,6 +19,7 @@ export default class CreatePollModal extends Modal { this.endDate = Stream(); this.publicPoll = Stream(false); + this.hideVotes = Stream(false); this.allowMultipleVotes = Stream(false); this.maxVotes = Stream(0); @@ -37,6 +38,9 @@ export default class CreatePollModal extends Modal { this.question(poll.question); this.publicPoll(poll.publicPoll); + this.hideVotes(poll.hideVotes); + this.allowMultipleVotes(poll.allowMultipleVotes); + this.maxVotes(poll.maxVotes || 0); this.endDate(this.formatDate(poll.endDate)); @@ -135,6 +139,16 @@ export default class CreatePollModal extends Modal { 20 ); + items.add( + 'hide-votes', +
+ + {app.translator.trans('fof-polls.forum.modal.hide_votes_label')} + +
, + 20 + ); + items.add( 'allow-multiple-votes',
diff --git a/js/src/forum/components/EditPollModal.js b/js/src/forum/components/EditPollModal.js index 606819b8..0fc47669 100755 --- a/js/src/forum/components/EditPollModal.js +++ b/js/src/forum/components/EditPollModal.js @@ -18,6 +18,7 @@ export default class EditPollModal extends CreatePollModal { this.endDate = Stream(this.formatDate(this.poll.endDate())); this.publicPoll = Stream(this.poll.publicPoll()); this.allowMultipleVotes = Stream(this.poll.allowMultipleVotes()); + this.hideVotes = Stream(this.poll.hideVotes()); this.maxVotes = Stream(this.poll.maxVotes() || 0); if (this.endDate() && dayjs(this.poll.endDate()).isAfter(dayjs())) { @@ -95,6 +96,7 @@ export default class EditPollModal extends CreatePollModal { question: this.question(), endDate: this.dateToTimestamp(this.endDate()), publicPoll: this.publicPoll(), + hideVotes: this.hideVotes(), allowMultipleVotes: this.allowMultipleVotes(), maxVotes: this.maxVotes(), options, diff --git a/js/src/forum/components/PostPoll.js b/js/src/forum/components/PostPoll.js index 60bfdca7..98f0d7f9 100644 --- a/js/src/forum/components/PostPoll.js +++ b/js/src/forum/components/PostPoll.js @@ -86,6 +86,7 @@ export default class PostPoll extends Component { // isNaN(null) is false, so we have to check type directly now that API always returns the field const canSeeVoteCount = typeof votes === 'number'; const isDisabled = this.loadingOptions || (hasVoted && !poll.canChangeVote()); + const width = canSeeVoteCount ? percent : (Number(voted) / (poll.myVotes()?.length || 1)) * 100; const bar = (
@@ -96,7 +97,7 @@ export default class PostPoll extends Component { )} -
+