Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update poll #3111

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions components/status/StatusPoll.vue
Original file line number Diff line number Diff line change
@@ -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()

@@ -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>

@@ -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
@@ -637,7 +637,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",
3 changes: 2 additions & 1 deletion locales/fr-FR.json
Original file line number Diff line number Diff line change
@@ -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",