Skip to content

Commit 58a3b0c

Browse files
committed
implement like update
1 parent dfc4d7d commit 58a3b0c

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

app/components/Package/LikeCard.vue

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { useAtproto } from '~/composables/atproto/useAtproto'
3+
import { togglePackageLike } from '~/utils/atproto/likes'
24
const props = defineProps<{
35
packageUrl: string
46
}>()
@@ -14,7 +16,7 @@ const { user } = useAtproto()
1416
1517
const authModal = useModal('auth-modal')
1618
17-
const { data: likesData } = useFetch(() => `/api/social/likes/${name}`, {
19+
const { data: likesData } = useFetch(() => `/api/social/likes/${name.value}`, {
1820
default: () => ({ totalLikes: 0, userHasLiked: false }),
1921
server: false,
2022
})
@@ -41,7 +43,7 @@ const likeAction = async () => {
4143
isLikeActionPending.value = true
4244
4345
try {
44-
const result = await togglePackageLike(name, currentlyLiked, user.value?.handle)
46+
const result = await togglePackageLike(name.value, currentlyLiked, user.value?.handle)
4547
4648
isLikeActionPending.value = false
4749
@@ -55,7 +57,7 @@ const likeAction = async () => {
5557
userHasLiked: currentlyLiked,
5658
}
5759
}
58-
} catch {
60+
} catch (e) {
5961
// Revert on error
6062
likesData.value = {
6163
totalLikes: currentLikes,
@@ -70,34 +72,38 @@ const likeAction = async () => {
7072
<NuxtLink :to="packageRoute(name)">
7173
<BaseCard class="group font-mono flex justify-between">
7274
{{ name }}
73-
<ClientOnly>
74-
<TooltipApp
75-
:text="likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')"
76-
position="bottom"
77-
>
78-
<button
79-
@click="likeAction"
80-
type="button"
81-
:title="likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')"
82-
class="inline-flex items-center gap-1.5 font-mono text-sm text-fg hover:text-fg-muted transition-colors duration-200"
83-
:aria-label="
84-
likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')
85-
"
75+
<div class="flex items-center gap-4">
76+
<ClientOnly>
77+
<TooltipApp
78+
:text="likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')"
79+
position="bottom"
8680
>
87-
<span
88-
:class="
89-
likesData?.userHasLiked
90-
? 'i-lucide-heart-minus text-red-500'
91-
: 'i-lucide-heart-plus'
81+
<button
82+
@click.prevent="likeAction"
83+
type="button"
84+
:title="
85+
likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')
9286
"
93-
class="w-4 h-4"
94-
aria-hidden="true"
95-
/>
96-
<span>{{ formatCompactNumber(likesData?.totalLikes ?? 0, { decimals: 1 }) }}</span>
97-
</button>
98-
</TooltipApp>
99-
</ClientOnly>
100-
<p class="transition-transform duration-150 group-hover:rotate-45">↗</p>
87+
class="inline-flex items-center gap-1.5 font-mono text-sm text-fg hover:text-fg-muted transition-colors duration-200"
88+
:aria-label="
89+
likesData?.userHasLiked ? $t('package.likes.unlike') : $t('package.likes.like')
90+
"
91+
>
92+
<span
93+
:class="
94+
likesData?.userHasLiked
95+
? 'i-lucide-heart-minus text-red-500'
96+
: 'i-lucide-heart-plus'
97+
"
98+
class="w-4 h-4"
99+
aria-hidden="true"
100+
/>
101+
<span>{{ formatCompactNumber(likesData?.totalLikes ?? 0, { decimals: 1 }) }}</span>
102+
</button>
103+
</TooltipApp>
104+
</ClientOnly>
105+
<p class="transition-transform duration-150 group-hover:rotate-45 pt-1">↗</p>
106+
</div>
101107
</BaseCard>
102108
</NuxtLink>
103109
</template>

0 commit comments

Comments
 (0)