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 1 commit
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
Next Next commit
feat: update poll
Clovis committed Dec 29, 2024
commit 2ca075aad5d791e91a8988e9c05e3ffaa9ab4ac9
42 changes: 33 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,21 @@ async function vote(e: Event) {
await client.value.v1.polls.$select(poll.id).votes.create({ choices })
}

async function refresh() {
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 +87,23 @@ 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>
<div flex="~ inline" gap-x-1>
<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>
<div>
<button 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",