refs #874 Hold polls data in NewTootModal component

This commit is contained in:
AkiraFukushima 2019-07-16 21:51:33 +09:00
parent e558945fca
commit d95ec64513
2 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,7 @@
</div>
<Status v-model="status" :opened="newTootModal" :fixCursorPos="hashtagInserting" @paste="onPaste" @toot="toot" />
</el-form>
<Poll v-if="openPoll"></Poll>
<Poll v-if="openPoll" v-model="polls" @addPoll="addPoll" @removePoll="removePoll"></Poll>
<div class="preview">
<div class="image-wrapper" v-for="media in attachedMedias" v-bind:key="media.id">
<img :src="media.preview_url" class="preview-image" />
@ -141,7 +141,8 @@ export default {
spoiler: '',
showContentWarning: false,
visibilityList: Visibility,
openPoll: false
openPoll: false,
polls: ['', '']
}
},
computed: {
@ -335,6 +336,12 @@ export default {
},
togglePollForm() {
this.openPoll = !this.openPoll
},
addPoll() {
this.polls.push('')
},
removePoll(id) {
this.polls.splice(id, 1)
}
}
}

View File

@ -1,9 +1,9 @@
<template>
<div class="poll">
<ul class="poll-list">
<li class="poll-option" v-for="(option, id) in polls" v-bind:key="id">
<li class="poll-option" v-for="(option, id) in value" v-bind:key="id">
<el-radio :disabled="true" :label="id">
<el-input :placeholder="`choice ${id}`" v-model="polls[id]" size="small"></el-input>
<el-input :placeholder="`choice ${id}`" :value="value[id]" @input="value => updateOption(value, id)" size="small"></el-input>
<el-button class="remove-poll" type="text" @click="removePoll(id)" size="small"><icon name="times"></icon></el-button>
</el-radio>
</li>
@ -15,17 +15,17 @@
<script>
export default {
name: 'poll',
data() {
return {
polls: ['', '']
}
},
props: ['value'],
methods: {
addPoll() {
this.polls.push('')
this.$emit('addPoll')
},
removePoll(id) {
this.polls.splice(id, 1)
this.$emit('removePoll', id)
},
updateOption(item, index) {
const newValue = [...this.value.slice(0, index), item, ...this.value.slice(index + 1)]
this.$emit('input', newValue)
}
}
}