feat: update poll (#3111)
Co-authored-by: Clovis <clovis@synapse-medicine.com> Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
This commit is contained in:
parent
e52b34c62d
commit
be6aa1e878
3 changed files with 45 additions and 11 deletions
|
@ -14,6 +14,7 @@ const timeAgoOptions = useTimeAgoOptions()
|
||||||
const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions)
|
const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions)
|
||||||
const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!)
|
const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!)
|
||||||
const { formatPercentage } = useHumanReadableNumber()
|
const { formatPercentage } = useHumanReadableNumber()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
const { client } = useMasto()
|
const { client } = useMasto()
|
||||||
|
|
||||||
|
@ -39,6 +40,25 @@ async function vote(e: Event) {
|
||||||
await client.value.v1.polls.$select(poll.id).votes.create({ choices })
|
await client.value.v1.polls.$select(poll.id).votes.create({ choices })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
if (loading.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const newPoll = await client.value.v1.polls.$select(poll.id).fetch()
|
||||||
|
Object.assign(poll, newPoll)
|
||||||
|
cacheStatus({ ...status, poll: newPoll }, undefined, true)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
|
const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -71,15 +91,27 @@ const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div text-sm flex="~ inline" gap-x-1 text-secondary>
|
<div text-sm text-secondary flex justify-between items-center gap-3>
|
||||||
|
<div flex gap-x-1 flex-wrap>
|
||||||
|
<div inline-block>
|
||||||
<CommonLocalizedNumber
|
<CommonLocalizedNumber
|
||||||
keypath="status.poll.count"
|
keypath="status.poll.count"
|
||||||
:count="poll.votesCount"
|
:count="poll.votesCount"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
·
|
·
|
||||||
|
<div inline-block>
|
||||||
<CommonTooltip v-if="poll.expiresAt" :content="expiredTimeFormatted" class="inline-block" placement="right">
|
<CommonTooltip v-if="poll.expiresAt" :content="expiredTimeFormatted" class="inline-block" placement="right">
|
||||||
<time :datetime="poll.expiresAt!">{{ $t(poll.expired ? 'status.poll.finished' : 'status.poll.ends', [expiredTimeAgo]) }}</time>
|
<time :datetime="poll.expiresAt!">{{ $t(poll.expired ? 'status.poll.finished' : 'status.poll.ends', [expiredTimeAgo]) }}</time>
|
||||||
</CommonTooltip>
|
</CommonTooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div v-if="!poll.expired">
|
||||||
|
<button whitespace-nowrap flex gap-1 items-center hover:text-primary @click="refresh">
|
||||||
|
<div text-xs :class="loading ? 'animate-spin' : ''" i-ri:loop-right-line />
|
||||||
|
{{ $t('status.poll.update') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -639,7 +639,8 @@
|
||||||
"poll": {
|
"poll": {
|
||||||
"count": "{0} votes|{0} vote|{0} votes",
|
"count": "{0} votes|{0} vote|{0} votes",
|
||||||
"ends": "ends {0}",
|
"ends": "ends {0}",
|
||||||
"finished": "finished {0}"
|
"finished": "finished {0}",
|
||||||
|
"update": "Update poll"
|
||||||
},
|
},
|
||||||
"replying_to": "Replying to {0}",
|
"replying_to": "Replying to {0}",
|
||||||
"show_full_thread": "Show Full thread",
|
"show_full_thread": "Show Full thread",
|
||||||
|
|
|
@ -585,7 +585,8 @@
|
||||||
"poll": {
|
"poll": {
|
||||||
"count": "{0} votes",
|
"count": "{0} votes",
|
||||||
"ends": "se clôt {0}",
|
"ends": "se clôt {0}",
|
||||||
"finished": "clos {0}"
|
"finished": "clos {0}",
|
||||||
|
"update": "Mettre à jour les résultats"
|
||||||
},
|
},
|
||||||
"replying_to": "Répondre à {0}",
|
"replying_to": "Répondre à {0}",
|
||||||
"show_full_thread": "Voir le fil de discussion complet",
|
"show_full_thread": "Voir le fil de discussion complet",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue