poll form mini-refactor

This commit is contained in:
Henry Jameson 2026-07-22 01:23:11 +03:00
commit 9e5f24138b
4 changed files with 41 additions and 44 deletions

View file

@ -16,42 +16,45 @@ export default {
},
name: 'PollForm',
props: {
visible: {},
params: {
visible: Boolean,
modelValue: {
type: Object,
required: true,
required: false,
default: null,
},
},
emits: ['update:modelValue'],
computed: {
pollType: {
get() {
return pollFallback(this.params, 'pollType')
return pollFallback(this.modelValue, 'pollType')
},
set(newVal) {
this.params.pollType = newVal
this.$emit('update:modelValue', { ...this.modelValue, pollType: newVal })
},
},
options() {
const hasOptions = !!this.params.options
if (!hasOptions) {
this.params.options = pollFallback(this.params, 'options')
options: {
get() {
return pollFallback(this.modelValue, 'options')
},
set(newVal) {
this.$emit('update:modelValue', { ...this.modelValue, options: newVal })
}
return this.params.options
},
expiryAmount: {
get() {
return pollFallback(this.params, 'expiryAmount')
return pollFallback(this.modelValue, 'expiryAmount')
},
set(newVal) {
this.params.expiryAmount = newVal
this.$emit('update:modelValue', { ...this.modelValue, expiryAmount: newVal })
},
},
expiryUnit: {
get() {
return pollFallback(this.params, 'expiryUnit')
return pollFallback(this.modelValue, 'expiryUnit')
},
set(newVal) {
this.params.expiryUnit = newVal
this.$emit('update:modelValue', { ...this.modelValue, expiryUnit: newVal })
},
},
pollLimits() {
@ -88,12 +91,6 @@ export default {
},
},
methods: {
clear() {
this.pollType = 'single'
this.options = ['', '']
this.expiryAmount = 10
this.expiryUnit = 'minutes'
},
nextOption(index) {
const element = this.$el.querySelector(`#poll-${index + 1}`)
if (element) {
@ -110,7 +107,7 @@ export default {
},
addOption() {
if (this.options.length < this.maxOptions) {
this.options.push('')
this.options = [...this.options, '']
return true
}
return false
@ -118,8 +115,12 @@ export default {
deleteOption(index) {
if (this.options.length > 2) {
this.options.splice(index, 1)
this.options = this.options
}
},
updateOption(index, value) {
this.options = this.options
},
convertExpiryToUnit(unit, amount) {
// Note: we want seconds and not milliseconds
return DateUtils.secondsToUnit(unit, amount)

View file

@ -18,6 +18,7 @@
:placeholder="$t('polls.option')"
:maxlength="maxLength"
@keydown.enter.stop.prevent="nextOption(index)"
@change="updateOption"
>
</div>
<button

View file

@ -306,11 +306,11 @@ const PostStatusForm = {
},
// -Poll
hasPoll() {
this.newStatus.poll != null
return this.newStatus.poll != null
},
// -Quotes
hasQuote() {
this.newStatus.quote !== null
return this.newStatus.quote !== null
},
quotable() {
return this.quotingAvailable && this.replyTo
@ -350,9 +350,13 @@ const PostStatusForm = {
return this.newStatus.quote?.thread
},
set(value) {
this.newStatus.quote = {}
this.newStatus.quote.thread = value
this.newStatus.quote.id = value ? this.replyTo : ''
if (value) {
this.newStatus.quote = {}
this.newStatus.quote.thread = value
this.newStatus.quote.id = value ? this.replyTo : ''
} else {
this.newStatus.quote = null
}
},
},
@ -567,19 +571,15 @@ const PostStatusForm = {
clearStatus() {
const newStatus = this.newStatus
this.saveInhibited = true
this.newStatus = {
status: '',
mentionsLine: '',
spoilerText: '',
files: [],
visibility: newStatus.visibility,
contentType: newStatus.contentType,
poll: {},
quote: {},
mediaDescriptions: {},
}
this.newStatus.status = ''
this.newStatus.mentionsLine = '',
this.newStatus.spoilerText = '',
this.newStatus.files = [],
this.newStatus.poll = null,
this.newStatus.quote = null,
this.newStatus.mediaDescriptions = {},
this.$refs.mediaUpload && this.$refs.mediaUpload.clearFile()
this.clearPollForm()
this.clearQuoteForm()
if (this.preserveFocus) {
this.$nextTick(() => {
@ -920,11 +920,6 @@ const PostStatusForm = {
setPoll(poll) {
this.newStatus.poll = poll
},
clearPollForm() {
if (this.$refs.pollForm) {
this.$refs.pollForm.clear()
}
},
clearQuoteForm() {
if (this.$refs.quoteForm) {
this.$refs.quoteForm.clear()

View file

@ -271,7 +271,7 @@
v-if="pollsAvailable"
ref="pollForm"
:visible="pollFormVisible"
:params="newStatus.poll"
v-model="newStatus.poll"
/>
<QuoteForm
v-if="quotingAvailable"