mirror of
https://github.com/ArthurDanjou/artsite.git
synced 2026-01-31 20:29:42 +01:00
Use cookie for like
This commit is contained in:
@@ -22,8 +22,7 @@ const { copy, copied } = useClipboard({
|
|||||||
useSeoMeta({
|
useSeoMeta({
|
||||||
title: post.value?.title,
|
title: post.value?.title,
|
||||||
description: post.value?.description,
|
description: post.value?.description,
|
||||||
author: 'Arthur Danjou',
|
author: 'Arthur Danjou'
|
||||||
image: post.value?.cover
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function getDetails() {
|
function getDetails() {
|
||||||
@@ -36,9 +35,15 @@ function getDetails() {
|
|||||||
return `${likes} ${like} · ${views} ${view}`
|
return `${likes} ${like} · ${views} ${view}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const likeCookie = useCookie<boolean>(`post:like:${route.params.slug}`, {
|
||||||
|
maxAge: 7200
|
||||||
|
})
|
||||||
|
|
||||||
async function handleLike() {
|
async function handleLike() {
|
||||||
|
if (likeCookie.value) return
|
||||||
await $fetch(`/api/posts/like/${route.params.slug}`, { method: 'PUT' })
|
await $fetch(`/api/posts/like/${route.params.slug}`, { method: 'PUT' })
|
||||||
await refresh()
|
await refresh()
|
||||||
|
likeCookie.value = true
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -107,7 +112,7 @@ async function handleLike() {
|
|||||||
<div class="flex gap-4 items-center flex-wrap">
|
<div class="flex gap-4 items-center flex-wrap">
|
||||||
<UButton
|
<UButton
|
||||||
:label="postDB?.likes > 1 ? `${postDB?.likes} likes` : `${postDB?.likes} like`"
|
:label="postDB?.likes > 1 ? `${postDB?.likes} likes` : `${postDB?.likes} like`"
|
||||||
color="white"
|
:color="likeCookie ? 'red': 'white'"
|
||||||
icon="i-ph-heart-duotone"
|
icon="i-ph-heart-duotone"
|
||||||
size="lg"
|
size="lg"
|
||||||
variant="solid"
|
variant="solid"
|
||||||
|
|||||||
Reference in New Issue
Block a user