Skip to content

Commit 02d0802

Browse files
committed
fix: fix +1 state issue
1 parent 7965e70 commit 02d0802

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

app/components/Package/Header.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ const { user } = useAtproto()
186186
187187
const likeAnimKey = shallowRef(0)
188188
const showLikeFloat = shallowRef(false)
189+
const likeFloatKey = shallowRef(0)
190+
let likeFloatTimer: ReturnType<typeof setTimeout> | null = null
189191
190192
const heartAnimStyle = computed(() => {
191193
if (likeAnimKey.value === 0) return {}
@@ -226,9 +228,15 @@ const likeAction = async () => {
226228
likeAnimKey.value++
227229
228230
if (!currentlyLiked) {
231+
if (likeFloatTimer !== null) {
232+
clearTimeout(likeFloatTimer)
233+
likeFloatTimer = null
234+
}
235+
likeFloatKey.value++
229236
showLikeFloat.value = true
230-
setTimeout(() => {
237+
likeFloatTimer = setTimeout(() => {
231238
showLikeFloat.value = false
239+
likeFloatTimer = null
232240
}, 850)
233241
}
234242
@@ -315,7 +323,13 @@ const likeAction = async () => {
315323
strategy="fixed"
316324
>
317325
<div :class="$style.likeWrapper">
318-
<span v-if="showLikeFloat" aria-hidden="true" :class="$style.likeFloat">+1</span>
326+
<span
327+
v-if="showLikeFloat"
328+
:key="likeFloatKey"
329+
aria-hidden="true"
330+
:class="$style.likeFloat"
331+
>+1</span
332+
>
319333
<ButtonBase
320334
@click="likeAction"
321335
size="medium"

0 commit comments

Comments
 (0)