Skip to content

Commit

Permalink
Add: Confirm vote
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 authored and mei23 committed Nov 18, 2022
1 parent c242c07 commit 7e576c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions locales/en-US.yml
Expand Up @@ -730,6 +730,7 @@ common/views/components/poll.vue:
remaining-hours: "{h} hours, and {m} minutes remain"
remaining-minutes: "{m} minutes, and {s} seconds remaining"
remaining-seconds: "{s} seconds remaining"
vote-confirm: "Do you want to vote?"
common/views/components/poll-editor.vue:
no-only-one-choice: "At least two choices are required"
choice-n: "Choice {}"
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Expand Up @@ -778,6 +778,7 @@ common/views/components/poll.vue:
remaining-hours: "終了まであと{h}時間{m}分"
remaining-minutes: "終了まであと{m}分{s}秒"
remaining-seconds: "終了まであと{s}秒"
vote-confirm: "投票しますか?"

common/views/components/poll-editor.vue:
no-only-one-choice: "アンケートには、選択肢が最低2つ必要です"
Expand Down
34 changes: 21 additions & 13 deletions src/client/app/common/views/components/poll.vue
Expand Up @@ -78,20 +78,28 @@ export default Vue.extend({
},
vote(id) {
if (this.closed || !this.poll.multiple && this.poll.choices.some(c => c.isVoted)) return;
this.$root.api('notes/polls/vote', {
noteId: this.note.id,
choice: id
}).then(() => {
for (const c of this.poll.choices) {
if (c.id == id) {
c.votes++;
Vue.set(c, 'isVoted', true);
this.$root.dialog({
type: 'warning',
text: this.$t('vote-confirm'),
showCancelButton: true,
}).then(({ canceled, result }) => {
if (canceled) return;
this.$root.api('notes/polls/vote', {
noteId: this.note.id,
choice: id
}).then(() => {
for (const c of this.poll.choices) {
if (c.id == id) {
c.votes++;
Vue.set(c, 'isVoted', true);
}
}
}
if (!this.showResult) this.showResult = !this.poll.multiple;
});
this.$emit('voted');
},
if (!this.showResult) this.showResult = !this.poll.multiple;
});
this.$emit('voted');
},
}
});
</script>
Expand Down

0 comments on commit 7e576c0

Please sign in to comment.