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',
|
name: 'PollForm',
|
||||||
props: {
|
props: {
|
||||||
visible: {},
|
visible: Boolean,
|
||||||
params: {
|
modelValue: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: false,
|
||||||
|
default: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: ['update:modelValue'],
|
||||||
computed: {
|
computed: {
|
||||||
pollType: {
|
pollType: {
|
||||||
get() {
|
get() {
|
||||||
return pollFallback(this.params, 'pollType')
|
return pollFallback(this.modelValue, 'pollType')
|
||||||
},
|
},
|
||||||
set(newVal) {
|
set(newVal) {
|
||||||
this.params.pollType = newVal
|
this.$emit('update:modelValue', { ...this.modelValue, pollType: newVal })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options() {
|
options: {
|
||||||
const hasOptions = !!this.params.options
|
get() {
|
||||||
if (!hasOptions) {
|
return pollFallback(this.modelValue, 'options')
|
||||||
this.params.options = pollFallback(this.params, 'options')
|
},
|
||||||
|
set(newVal) {
|
||||||
|
this.$emit('update:modelValue', { ...this.modelValue, options: newVal })
|
||||||
}
|
}
|
||||||
return this.params.options
|
|
||||||
},
|
},
|
||||||
expiryAmount: {
|
expiryAmount: {
|
||||||
get() {
|
get() {
|
||||||
return pollFallback(this.params, 'expiryAmount')
|
return pollFallback(this.modelValue, 'expiryAmount')
|
||||||
},
|
},
|
||||||
set(newVal) {
|
set(newVal) {
|
||||||
this.params.expiryAmount = newVal
|
this.$emit('update:modelValue', { ...this.modelValue, expiryAmount: newVal })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expiryUnit: {
|
expiryUnit: {
|
||||||
get() {
|
get() {
|
||||||
return pollFallback(this.params, 'expiryUnit')
|
return pollFallback(this.modelValue, 'expiryUnit')
|
||||||
},
|
},
|
||||||
set(newVal) {
|
set(newVal) {
|
||||||
this.params.expiryUnit = newVal
|
this.$emit('update:modelValue', { ...this.modelValue, expiryUnit: newVal })
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pollLimits() {
|
pollLimits() {
|
||||||
|
|
@ -88,12 +91,6 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clear() {
|
|
||||||
this.pollType = 'single'
|
|
||||||
this.options = ['', '']
|
|
||||||
this.expiryAmount = 10
|
|
||||||
this.expiryUnit = 'minutes'
|
|
||||||
},
|
|
||||||
nextOption(index) {
|
nextOption(index) {
|
||||||
const element = this.$el.querySelector(`#poll-${index + 1}`)
|
const element = this.$el.querySelector(`#poll-${index + 1}`)
|
||||||
if (element) {
|
if (element) {
|
||||||
|
|
@ -110,7 +107,7 @@ export default {
|
||||||
},
|
},
|
||||||
addOption() {
|
addOption() {
|
||||||
if (this.options.length < this.maxOptions) {
|
if (this.options.length < this.maxOptions) {
|
||||||
this.options.push('')
|
this.options = [...this.options, '']
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
@ -118,8 +115,12 @@ export default {
|
||||||
deleteOption(index) {
|
deleteOption(index) {
|
||||||
if (this.options.length > 2) {
|
if (this.options.length > 2) {
|
||||||
this.options.splice(index, 1)
|
this.options.splice(index, 1)
|
||||||
|
this.options = this.options
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
updateOption(index, value) {
|
||||||
|
this.options = this.options
|
||||||
|
},
|
||||||
convertExpiryToUnit(unit, amount) {
|
convertExpiryToUnit(unit, amount) {
|
||||||
// Note: we want seconds and not milliseconds
|
// Note: we want seconds and not milliseconds
|
||||||
return DateUtils.secondsToUnit(unit, amount)
|
return DateUtils.secondsToUnit(unit, amount)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
:placeholder="$t('polls.option')"
|
:placeholder="$t('polls.option')"
|
||||||
:maxlength="maxLength"
|
:maxlength="maxLength"
|
||||||
@keydown.enter.stop.prevent="nextOption(index)"
|
@keydown.enter.stop.prevent="nextOption(index)"
|
||||||
|
@change="updateOption"
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -306,11 +306,11 @@ const PostStatusForm = {
|
||||||
},
|
},
|
||||||
// -Poll
|
// -Poll
|
||||||
hasPoll() {
|
hasPoll() {
|
||||||
this.newStatus.poll != null
|
return this.newStatus.poll != null
|
||||||
},
|
},
|
||||||
// -Quotes
|
// -Quotes
|
||||||
hasQuote() {
|
hasQuote() {
|
||||||
this.newStatus.quote !== null
|
return this.newStatus.quote !== null
|
||||||
},
|
},
|
||||||
quotable() {
|
quotable() {
|
||||||
return this.quotingAvailable && this.replyTo
|
return this.quotingAvailable && this.replyTo
|
||||||
|
|
@ -350,9 +350,13 @@ const PostStatusForm = {
|
||||||
return this.newStatus.quote?.thread
|
return this.newStatus.quote?.thread
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
this.newStatus.quote = {}
|
if (value) {
|
||||||
this.newStatus.quote.thread = value
|
this.newStatus.quote = {}
|
||||||
this.newStatus.quote.id = value ? this.replyTo : ''
|
this.newStatus.quote.thread = value
|
||||||
|
this.newStatus.quote.id = value ? this.replyTo : ''
|
||||||
|
} else {
|
||||||
|
this.newStatus.quote = null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -567,19 +571,15 @@ const PostStatusForm = {
|
||||||
clearStatus() {
|
clearStatus() {
|
||||||
const newStatus = this.newStatus
|
const newStatus = this.newStatus
|
||||||
this.saveInhibited = true
|
this.saveInhibited = true
|
||||||
this.newStatus = {
|
this.newStatus.status = ''
|
||||||
status: '',
|
this.newStatus.mentionsLine = '',
|
||||||
mentionsLine: '',
|
this.newStatus.spoilerText = '',
|
||||||
spoilerText: '',
|
this.newStatus.files = [],
|
||||||
files: [],
|
this.newStatus.poll = null,
|
||||||
visibility: newStatus.visibility,
|
this.newStatus.quote = null,
|
||||||
contentType: newStatus.contentType,
|
this.newStatus.mediaDescriptions = {},
|
||||||
poll: {},
|
|
||||||
quote: {},
|
|
||||||
mediaDescriptions: {},
|
|
||||||
}
|
|
||||||
this.$refs.mediaUpload && this.$refs.mediaUpload.clearFile()
|
this.$refs.mediaUpload && this.$refs.mediaUpload.clearFile()
|
||||||
this.clearPollForm()
|
|
||||||
this.clearQuoteForm()
|
this.clearQuoteForm()
|
||||||
if (this.preserveFocus) {
|
if (this.preserveFocus) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
|
@ -920,11 +920,6 @@ const PostStatusForm = {
|
||||||
setPoll(poll) {
|
setPoll(poll) {
|
||||||
this.newStatus.poll = poll
|
this.newStatus.poll = poll
|
||||||
},
|
},
|
||||||
clearPollForm() {
|
|
||||||
if (this.$refs.pollForm) {
|
|
||||||
this.$refs.pollForm.clear()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
clearQuoteForm() {
|
clearQuoteForm() {
|
||||||
if (this.$refs.quoteForm) {
|
if (this.$refs.quoteForm) {
|
||||||
this.$refs.quoteForm.clear()
|
this.$refs.quoteForm.clear()
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@
|
||||||
v-if="pollsAvailable"
|
v-if="pollsAvailable"
|
||||||
ref="pollForm"
|
ref="pollForm"
|
||||||
:visible="pollFormVisible"
|
:visible="pollFormVisible"
|
||||||
:params="newStatus.poll"
|
v-model="newStatus.poll"
|
||||||
/>
|
/>
|
||||||
<QuoteForm
|
<QuoteForm
|
||||||
v-if="quotingAvailable"
|
v-if="quotingAvailable"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue