-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFollowButton.vue
59 lines (53 loc) · 1.42 KB
/
FollowButton.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
<button
type="button"
class="fr-btn fr-btn--sm fr-btn--secondary fr-btn--secondary-grey-500 follow-button"
:disabled="readOnlyEnabled"
@click.prevent="toggleFollow"
>
<span>
<RiStarFill
v-if="following"
:class="{ 'animate-ping': animating }"
class="size-4"
/>
<RiStarLine
v-else
:class="{ 'animate-ping': animating }"
class="size-4"
/>
</span>
<span class="fr-ml-1w">
<template v-if="following">{{ $t("Remove from favourites") }}</template>
<template v-else>{{ $t("Add to favourites") }}</template>
</span>
</button>
</template>
<script setup lang="ts">
import { RiStarFill, RiStarLine } from '@remixicon/vue'
import { ref } from 'vue'
const props = defineProps<{
url: string
following?: boolean
}>()
const config = useRuntimeConfig()
const { $api } = useNuxtApp()
const animating = ref(false)
const following = ref(props.following)
const readOnlyEnabled = config.public.readOnlyMode
async function toggleFollow() {
const me = useMaybeMe()
if (!me.value) {
const localePath = useLocalePath()
return navigateTo(localePath('/login'), { external: true })
}
await $api(props.url, {
method: following.value ? 'DELETE' : 'POST',
})
following.value = !following.value
if (following.value) {
animating.value = true
setTimeout(() => (animating.value = false), 1300)
}
}
</script>