Skip to content

Commit

Permalink
feat: update poll (#3111)
Browse files Browse the repository at this point in the history
Co-authored-by: Clovis <[email protected]>
Co-authored-by: TAKAHASHI Shuuji <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent e52b34c commit be6aa1e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
50 changes: 41 additions & 9 deletions components/status/StatusPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const timeAgoOptions = useTimeAgoOptions()
const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions)
const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!)
const { formatPercentage } = useHumanReadableNumber()
const loading = ref(false)
const { client } = useMasto()
Expand All @@ -39,6 +40,25 @@ async function vote(e: Event) {
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)
</script>

Expand Down Expand Up @@ -71,15 +91,27 @@ const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
</div>
</div>
</template>
<div text-sm flex="~ inline" gap-x-1 text-secondary>
<CommonLocalizedNumber
keypath="status.poll.count"
:count="poll.votesCount"
/>
&middot;
<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>
</CommonTooltip>
<div text-sm text-secondary flex justify-between items-center gap-3>
<div flex gap-x-1 flex-wrap>
<div inline-block>
<CommonLocalizedNumber
keypath="status.poll.count"
:count="poll.votesCount"
/>
</div>
&middot;
<div inline-block>
<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>
</CommonTooltip>
</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>
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@
"poll": {
"count": "{0} votes|{0} vote|{0} votes",
"ends": "ends {0}",
"finished": "finished {0}"
"finished": "finished {0}",
"update": "Update poll"
},
"replying_to": "Replying to {0}",
"show_full_thread": "Show Full thread",
Expand Down
3 changes: 2 additions & 1 deletion locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@
"poll": {
"count": "{0} votes",
"ends": "se clôt {0}",
"finished": "clos {0}"
"finished": "clos {0}",
"update": "Mettre à jour les résultats"
},
"replying_to": "Répondre à {0}",
"show_full_thread": "Voir le fil de discussion complet",
Expand Down

0 comments on commit be6aa1e

Please sign in to comment.