Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 99be910

Browse files
Cl0v1sClovisshuuji3
authored andcommittedFeb 6, 2025
feat: update poll (#3111)
Co-authored-by: Clovis <clovis@synapse-medicine.com> Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
1 parent c601c8b commit 99be910

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed
 

‎components/status/StatusPoll.vue

+41-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const timeAgoOptions = useTimeAgoOptions()
1414
const expiredTimeAgo = useTimeAgo(poll.expiresAt!, timeAgoOptions)
1515
const expiredTimeFormatted = useFormattedDateTime(poll.expiresAt!)
1616
const { formatPercentage } = useHumanReadableNumber()
17+
const loading = ref(false)
1718
1819
const { client } = useMasto()
1920
@@ -39,6 +40,25 @@ async function vote(e: Event) {
3940
await client.value.v1.polls.$select(poll.id).votes.create({ choices })
4041
}
4142
43+
async function refresh() {
44+
if (loading.value) {
45+
return
46+
}
47+
48+
loading.value = true
49+
try {
50+
const newPoll = await client.value.v1.polls.$select(poll.id).fetch()
51+
Object.assign(poll, newPoll)
52+
cacheStatus({ ...status, poll: newPoll }, undefined, true)
53+
}
54+
catch (e) {
55+
console.error(e)
56+
}
57+
finally {
58+
loading.value = false
59+
}
60+
}
61+
4262
const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
4363
</script>
4464

@@ -71,15 +91,27 @@ const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
7191
</div>
7292
</div>
7393
</template>
74-
<div text-sm flex="~ inline" gap-x-1 text-secondary>
75-
<CommonLocalizedNumber
76-
keypath="status.poll.count"
77-
:count="poll.votesCount"
78-
/>
79-
&middot;
80-
<CommonTooltip v-if="poll.expiresAt" :content="expiredTimeFormatted" class="inline-block" placement="right">
81-
<time :datetime="poll.expiresAt!">{{ $t(poll.expired ? 'status.poll.finished' : 'status.poll.ends', [expiredTimeAgo]) }}</time>
82-
</CommonTooltip>
94+
<div text-sm text-secondary flex justify-between items-center gap-3>
95+
<div flex gap-x-1 flex-wrap>
96+
<div inline-block>
97+
<CommonLocalizedNumber
98+
keypath="status.poll.count"
99+
:count="poll.votesCount"
100+
/>
101+
</div>
102+
&middot;
103+
<div inline-block>
104+
<CommonTooltip v-if="poll.expiresAt" :content="expiredTimeFormatted" class="inline-block" placement="right">
105+
<time :datetime="poll.expiresAt!">{{ $t(poll.expired ? 'status.poll.finished' : 'status.poll.ends', [expiredTimeAgo]) }}</time>
106+
</CommonTooltip>
107+
</div>
108+
</div>
109+
<div v-if="!poll.expired">
110+
<button whitespace-nowrap flex gap-1 items-center hover:text-primary @click="refresh">
111+
<div text-xs :class="loading ? 'animate-spin' : ''" i-ri:loop-right-line />
112+
{{ $t('status.poll.update') }}
113+
</button>
114+
</div>
83115
</div>
84116
</div>
85117
</template>

‎locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@
639639
"poll": {
640640
"count": "{0} votes|{0} vote|{0} votes",
641641
"ends": "ends {0}",
642-
"finished": "finished {0}"
642+
"finished": "finished {0}",
643+
"update": "Update poll"
643644
},
644645
"replying_to": "Replying to {0}",
645646
"show_full_thread": "Show Full thread",

‎locales/fr-FR.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,8 @@
585585
"poll": {
586586
"count": "{0} votes",
587587
"ends": "se clôt {0}",
588-
"finished": "clos {0}"
588+
"finished": "clos {0}",
589+
"update": "Mettre à jour les résultats"
589590
},
590591
"replying_to": "Répondre à {0}",
591592
"show_full_thread": "Voir le fil de discussion complet",

0 commit comments

Comments
 (0)
Please sign in to comment.