poll form mini-refactor
This commit is contained in:
parent
8ff2575c3f
commit
9e5f24138b
4 changed files with 41 additions and 44 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
:placeholder="$t('polls.option')"
|
||||
:maxlength="maxLength"
|
||||
@keydown.enter.stop.prevent="nextOption(index)"
|
||||
@change="updateOption"
|
||||
>
|
||||
</div>
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@
|
|||
v-if="pollsAvailable"
|
||||
ref="pollForm"
|
||||
:visible="pollFormVisible"
|
||||
:params="newStatus.poll"
|
||||
v-model="newStatus.poll"
|
||||
/>
|
||||
<QuoteForm
|
||||
v-if="quotingAvailable"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue