Skip to content

Commit 4ca425f

Browse files
bteaghostdevv
andauthored
feat: load package like data add loading effect (#982)
Co-authored-by: Willow (GHOST) <git@willow.sh>
1 parent 4baf904 commit 4ca425f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

app/pages/package/[[org]]/[name].vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,16 @@ const { user } = useAtproto()
405405
406406
const authModal = useModal('auth-modal')
407407
408-
const { data: likesData } = useFetch(() => `/api/social/likes/${packageName.value}`, {
409-
default: () => ({ totalLikes: 0, userHasLiked: false }),
410-
server: false,
411-
})
408+
const { data: likesData, status: likeStatus } = useFetch(
409+
() => `/api/social/likes/${packageName.value}`,
410+
{
411+
default: () => ({ totalLikes: 0, userHasLiked: false }),
412+
server: false,
413+
},
414+
)
415+
const isLoadingLikeData = computed(
416+
() => likeStatus.value !== 'error' && likeStatus.value !== 'success',
417+
)
412418
413419
const isLikeActionPending = ref(false)
414420
@@ -614,11 +620,22 @@ onKeyStroke(
614620
<!-- Package likes -->
615621
<TooltipApp
616622
:text="
617-
likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')
623+
isLoadingLikeData
624+
? $t('common.loading')
625+
: likesData?.userHasLiked
626+
? $t('package.likes.unlike')
627+
: $t('package.likes.like')
618628
"
619629
position="bottom"
630+
class="items-center"
620631
>
632+
<span
633+
v-if="isLoadingLikeData"
634+
class="i-carbon-circle-dash w-3 h-3 motion-safe:animate-spin"
635+
aria-hidden="true"
636+
/>
621637
<button
638+
v-else
622639
@click="likeAction"
623640
type="button"
624641
:title="

0 commit comments

Comments
 (0)