Poll WIP (#231):

* muted participants can't vote
* removed "Choice N" from button labels.
This commit is contained in:
John Livingston
2024-07-05 11:00:37 +02:00
parent 6dda0cc44f
commit 14ffa90208
5 changed files with 11 additions and 10 deletions

View File

@ -4,7 +4,7 @@
import { tplPoll } from '../templates/poll.js'
import { CustomElement } from 'shared/components/element.js'
import { api } from '@converse/headless/core'
import { converse, api } from '@converse/headless/core'
import '../styles/poll.scss'
export default class MUCPollView extends CustomElement {
@ -30,7 +30,9 @@ export default class MUCPollView extends CustomElement {
render () {
const currentPoll = this.model?.get('current_poll')
return tplPoll(this, currentPoll)
const entered = this.model.session.get('connection_status') === converse.ROOMSTATUS.ENTERED
const canVote = entered && this.model.getOwnRole() !== 'visitor'
return tplPoll(this, currentPoll, canVote)
}
toggle (ev) {

View File

@ -31,9 +31,9 @@ function _tplPollEnd (el, currentPoll) {
</p>`
}
function _tplChoice (el, currentPoll, choice) {
function _tplChoice (el, currentPoll, choice, canVote) {
// eslint-disable-next-line no-undef
const i18nChoiceN = __(LOC_poll_choice_n).replace('{{N}}', choice.choice)
const i18nChoiceN = '' + choice.choice + ':'
const votes = choice.votes
const totalVotes = currentPoll.votes
@ -42,7 +42,7 @@ function _tplChoice (el, currentPoll, choice) {
<tr>
<td>
${
currentPoll.over
currentPoll.over || !canVote
? html`${i18nChoiceN}`
: html`
<button type="button" class="btn btn-primary btn-sm"
@ -75,7 +75,7 @@ function _tplChoice (el, currentPoll, choice) {
</tr>`
}
export function tplPoll (el, currentPoll) {
export function tplPoll (el, currentPoll, canVote) {
if (!currentPoll) {
return html``
}
@ -113,7 +113,7 @@ export function tplPoll (el, currentPoll) {
? ''
: html`
<table><tbody>
${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c))}
${repeat(currentPoll.choices ?? [], (c) => c.choice, (c) => _tplChoice(el, currentPoll, c, canVote))}
</tbody></table>
${_tplPollInstructions(el, currentPoll)}
${_tplPollEnd(el, currentPoll)}