@@ -14,6 +14,7 @@ const timeAgoOptions = useTimeAgoOptions()
14
14
const expiredTimeAgo = useTimeAgo (poll .expiresAt ! , timeAgoOptions )
15
15
const expiredTimeFormatted = useFormattedDateTime (poll .expiresAt ! )
16
16
const { formatPercentage } = useHumanReadableNumber ()
17
+ const loading = ref (false )
17
18
18
19
const { client } = useMasto ()
19
20
@@ -39,6 +40,25 @@ async function vote(e: Event) {
39
40
await client .value .v1 .polls .$select (poll .id ).votes .create ({ choices })
40
41
}
41
42
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
+
42
62
const votersCount = computed (() => poll .votersCount ?? poll .votesCount ?? 0 )
43
63
</script >
44
64
@@ -71,15 +91,27 @@ const votersCount = computed(() => poll.votersCount ?? poll.votesCount ?? 0)
71
91
</div >
72
92
</div >
73
93
</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
- · ;
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
+ · ;
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 >
83
115
</div >
84
116
</div >
85
117
</template >
0 commit comments