refs #874 Set expire in poll form

This commit is contained in:
AkiraFukushima 2019-07-17 01:36:19 +09:00
parent 7e1ca935de
commit f71e902463
4 changed files with 79 additions and 6 deletions

View File

@ -223,7 +223,16 @@
"pined_hashtag": "Pin the hashtag"
},
"poll": {
"add_choice": "Add a choice"
"add_choice": "Add a choice",
"expires": {
"5_minutes": "5 minutes",
"30_minutes": "30 minutes",
"1_hour": "1 hour",
"6_hours": "6 hours",
"1_day": "1 day",
"3_days": "3 days",
"7_days": "7 days"
}
}
},
"jump": {

View File

@ -14,7 +14,14 @@
</div>
<Status v-model="status" :opened="newTootModal" :fixCursorPos="hashtagInserting" @paste="onPaste" @toot="toot" />
</el-form>
<Poll v-if="openPoll" v-model="polls" @addPoll="addPoll" @removePoll="removePoll"></Poll>
<Poll
v-if="openPoll"
v-model="polls"
@addPoll="addPoll"
@removePoll="removePoll"
:defaultExpire="pollExpire"
@changeExpire="changeExpire"
></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" />
@ -142,7 +149,11 @@ export default {
showContentWarning: false,
visibilityList: Visibility,
openPoll: false,
polls: ['', '']
polls: ['', ''],
pollExpire: {
label: this.$t('modals.new_toot.poll.expires.1_day'),
value: 3600 * 24
}
}
},
computed: {
@ -219,6 +230,10 @@ export default {
close() {
this.filteredAccount = []
this.polls = ['', '']
this.pollExpire = {
label: this.$t('modals.new_toot.poll.expires.1_day'),
value: 3600 * 24
}
this.$store.dispatch('TimelineSpace/Modals/NewToot/resetMediaCount')
this.$store.dispatch('TimelineSpace/Modals/NewToot/closeModal')
},
@ -226,7 +241,8 @@ export default {
const form = {
status: this.status,
spoiler: this.spoiler,
polls: this.polls
polls: this.polls,
pollExpireSeconds: this.pollExpire.value
}
try {
@ -344,6 +360,9 @@ export default {
},
removePoll(id) {
this.polls.splice(id, 1)
},
changeExpire(obj) {
this.pollExpire = obj
}
}
}

View File

@ -9,13 +9,54 @@
</li>
</ul>
<el-button class="add-poll" type="info" size="small" @click="addPoll" plain>{{ $t('modals.new_toot.poll.add_choice') }}</el-button>
<el-select v-model="expiresIn" size="small" value-key="value" @change="changeExpire">
<el-option v-for="exp in expires" :key="exp.value" :label="exp.label" :value="exp"> </el-option>
</el-select>
</div>
</template>
<script>
export default {
name: 'poll',
props: ['value'],
props: ['value', 'defaultExpire'],
data() {
return {
expires: [
{
label: this.$t('modals.new_toot.poll.expires.5_minutes'),
value: 60 * 5
},
{
label: this.$t('modals.new_toot.poll.expires.30_minutes'),
value: 60 * 30
},
{
label: this.$t('modals.new_toot.poll.expires.1_hour'),
value: 3600
},
{
label: this.$t('modals.new_toot.poll.expires.6_hours'),
value: 3600 * 6
},
{
label: this.$t('modals.new_toot.poll.expires.1_day'),
value: 3600 * 24
},
{
label: this.$t('modals.new_toot.poll.expires.3_days'),
value: 3600 * 24 * 3
},
{
label: this.$t('modals.new_toot.poll.expires.7_days'),
value: 3600 * 24 * 7
}
],
expiresIn: null
}
},
created() {
this.expiresIn = this.defaultExpire
},
methods: {
addPoll() {
this.$emit('addPoll')
@ -26,6 +67,9 @@ export default {
updateOption(item, index) {
const newValue = [...this.value.slice(0, index), item, ...this.value.slice(index + 1)]
this.$emit('input', newValue)
},
changeExpire(exp) {
this.$emit('changeExpire', exp)
}
}
}

View File

@ -24,6 +24,7 @@ type TootForm = {
status: string
spoiler: string
polls: Array<string>
pollExpireSeconds: number
}
export type NewTootState = {
@ -206,7 +207,7 @@ const actions: ActionTree<NewTootState, RootState> = {
sensitive: state.sensitive,
spoiler_text: params.spoiler,
poll: {
expires_in: 86400,
expires_in: params.pollExpireSeconds,
multiple: false,
options: params.polls
}