biome format --write

This commit is contained in:
Henry Jameson 2026-01-06 16:22:52 +02:00
commit 9262e803ec
415 changed files with 54076 additions and 17419 deletions

View file

@ -10,83 +10,85 @@ export default {
components: {
Timeago,
RichContent,
Checkbox
Checkbox,
},
data () {
data() {
return {
loading: false,
choices: [],
randomSeed: genRandomSeed()
randomSeed: genRandomSeed(),
}
},
created () {
created() {
if (!usePollsStore().pollsObject[this.pollId]) {
usePollsStore().mergeOrAddPoll(this.basePoll)
}
usePollsStore().trackPoll(this.pollId)
},
unmounted () {
unmounted() {
usePollsStore().untrackPoll(this.pollId)
},
computed: {
pollId () {
pollId() {
return this.basePoll.id
},
poll () {
poll() {
const storePoll = usePollsStore().pollsObject[this.pollId]
return storePoll || {}
},
options () {
options() {
return (this.poll && this.poll.options) || []
},
expiresAt () {
expiresAt() {
return (this.poll && this.poll.expires_at) || null
},
expired () {
expired() {
return (this.poll && this.poll.expired) || false
},
expirationLabel () {
expirationLabel() {
if (this.$store.getters.mergedConfig.useAbsoluteTimeFormat) {
return this.expired ? 'polls.expired_at' : 'polls.expires_at'
} else {
return this.expired ? 'polls.expired' : 'polls.expires_in'
}
},
loggedIn () {
loggedIn() {
return this.$store.state.users.currentUser
},
showResults () {
showResults() {
return this.poll.voted || this.expired || !this.loggedIn
},
totalVotesCount () {
totalVotesCount() {
return this.poll.votes_count
},
containerClass () {
containerClass() {
return {
loading: this.loading
loading: this.loading,
}
},
choiceIndices () {
choiceIndices() {
// Convert array of booleans into an array of indices of the
// items that were 'true', so [true, false, false, true] becomes
// [0, 3].
return this.choices
.map((entry, index) => entry && index)
.filter(value => typeof value === 'number')
.filter((value) => typeof value === 'number')
},
isDisabled () {
isDisabled() {
const noChoice = this.choiceIndices.length === 0
return this.loading || noChoice
}
},
},
methods: {
percentageForOption (count) {
return this.totalVotesCount === 0 ? 0 : Math.round(count / this.totalVotesCount * 100)
percentageForOption(count) {
return this.totalVotesCount === 0
? 0
: Math.round((count / this.totalVotesCount) * 100)
},
resultTitle (option) {
resultTitle(option) {
return `${option.votes_count}/${this.totalVotesCount} ${this.$t('polls.votes')}`
},
activateOption (index, value) {
activateOption(index, value) {
let result
if (this.poll.multiple) {
result = this.choices || this.options.map(() => false)
@ -96,17 +98,21 @@ export default {
result[index] = value
this.choices = result
},
optionId (index) {
optionId(index) {
return `poll${this.poll.id}-${index}`
},
vote () {
vote() {
if (this.choiceIndices.length === 0) return
this.loading = true
usePollsStore().votePoll(
{ id: this.statusId, pollId: this.poll.id, choices: this.choiceIndices }
).then(() => {
this.loading = false
})
}
}
usePollsStore()
.votePoll({
id: this.statusId,
pollId: this.poll.id,
choices: this.choiceIndices,
})
.then(() => {
this.loading = false
})
},
},
}

View file

@ -2,34 +2,32 @@ import * as DateUtils from 'src/services/date_utils/date_utils.js'
import { pollFallback } from 'src/services/poll/poll.service.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import Select from '../select/select.vue'
import {
faTimes,
faPlus
} from '@fortawesome/free-solid-svg-icons'
import { faTimes, faPlus } from '@fortawesome/free-solid-svg-icons'
library.add(
faTimes,
faPlus
)
library.add(faTimes, faPlus)
export default {
components: {
Select
Select,
},
name: 'PollForm',
props: {
visible: {},
params: {
type: Object,
required: true
}
required: true,
},
},
computed: {
pollType: {
get () { return pollFallback(this.params, 'pollType') },
set (newVal) { this.params.pollType = newVal }
get() {
return pollFallback(this.params, 'pollType')
},
set(newVal) {
this.params.pollType = newVal
},
},
options () {
options() {
const hasOptions = !!this.params.options
if (!hasOptions) {
this.params.options = pollFallback(this.params, 'options')
@ -37,54 +35,62 @@ export default {
return this.params.options
},
expiryAmount: {
get () { return pollFallback(this.params, 'expiryAmount') },
set (newVal) { this.params.expiryAmount = newVal }
get() {
return pollFallback(this.params, 'expiryAmount')
},
set(newVal) {
this.params.expiryAmount = newVal
},
},
expiryUnit: {
get () { return pollFallback(this.params, 'expiryUnit') },
set (newVal) { this.params.expiryUnit = newVal }
get() {
return pollFallback(this.params, 'expiryUnit')
},
set(newVal) {
this.params.expiryUnit = newVal
},
},
pollLimits () {
pollLimits() {
return this.$store.state.instance.pollLimits
},
maxOptions () {
maxOptions() {
return this.pollLimits.max_options
},
maxLength () {
maxLength() {
return this.pollLimits.max_option_chars
},
expiryUnits () {
expiryUnits() {
const allUnits = ['minutes', 'hours', 'days']
const expiry = this.convertExpiryFromUnit
return allUnits.filter(
unit => this.pollLimits.max_expiration >= expiry(unit, 1)
(unit) => this.pollLimits.max_expiration >= expiry(unit, 1),
)
},
minExpirationInCurrentUnit () {
minExpirationInCurrentUnit() {
return Math.ceil(
this.convertExpiryToUnit(
this.expiryUnit,
this.pollLimits.min_expiration
)
this.pollLimits.min_expiration,
),
)
},
maxExpirationInCurrentUnit () {
maxExpirationInCurrentUnit() {
return Math.floor(
this.convertExpiryToUnit(
this.expiryUnit,
this.pollLimits.max_expiration
)
this.pollLimits.max_expiration,
),
)
}
},
},
methods: {
clear () {
clear() {
this.pollType = 'single'
this.options = ['', '']
this.expiryAmount = 10
this.expiryUnit = 'minutes'
},
nextOption (index) {
nextOption(index) {
const element = this.$el.querySelector(`#poll-${index + 1}`)
if (element) {
element.focus()
@ -98,30 +104,34 @@ export default {
}
}
},
addOption () {
addOption() {
if (this.options.length < this.maxOptions) {
this.options.push('')
return true
}
return false
},
deleteOption (index) {
deleteOption(index) {
if (this.options.length > 2) {
this.options.splice(index, 1)
}
},
convertExpiryToUnit (unit, amount) {
convertExpiryToUnit(unit, amount) {
// Note: we want seconds and not milliseconds
return DateUtils.secondsToUnit(unit, amount)
},
convertExpiryFromUnit (unit, amount) {
convertExpiryFromUnit(unit, amount) {
return DateUtils.unitToSeconds(unit, amount)
},
expiryAmountChange () {
this.expiryAmount =
Math.max(this.minExpirationInCurrentUnit, this.expiryAmount)
this.expiryAmount =
Math.min(this.maxExpirationInCurrentUnit, this.expiryAmount)
}
}
expiryAmountChange() {
this.expiryAmount = Math.max(
this.minExpirationInCurrentUnit,
this.expiryAmount,
)
this.expiryAmount = Math.min(
this.maxExpirationInCurrentUnit,
this.expiryAmount,
)
},
},
}

View file

@ -5,8 +5,8 @@ export default {
{
directives: {
background: '--accent',
opacity: 0.5
}
}
]
opacity: 0.5,
},
},
],
}