funkwhale/front/src/components/audio/LibraryFollowButton.vue

52 wiersze
1.4 KiB
Vue
Czysty Zwykły widok Historia

2022-07-11 00:31:08 +00:00
<script setup lang="ts">
import type { Library } from '~/types'
import { computed } from 'vue'
import { useStore } from '~/store'
2022-08-30 20:23:17 +00:00
interface Events {
(e: 'unfollowed'): void
(e: 'followed'): void
}
2022-07-11 00:31:08 +00:00
interface Props {
library: Library
}
2022-08-30 20:23:17 +00:00
const emit = defineEmits<Events>()
2022-07-11 00:31:08 +00:00
const props = defineProps<Props>()
const store = useStore()
const follow = computed(() => store.getters['libraries/follow'](props.library.uuid))
const isPending = computed(() => follow.value && follow.value.approved === null)
const isApproved = computed(() => follow.value && (follow.value?.approved === true || (isPending.value && props.library.privacy_level === 'everyone')))
const toggle = () => {
if (isPending.value || isApproved.value) {
emit('unfollowed')
} else {
emit('followed')
}
return store.dispatch('libraries/toggle', props.library.uuid)
}
</script>
2021-12-06 10:35:20 +00:00
<template>
<button
:class="['ui', 'pink', {'inverted': isApproved || isPending}, {'favorited': isApproved}, 'icon', 'labeled', 'button']"
@click.stop="toggle"
>
<i class="heart icon" />
2022-11-26 23:16:46 +00:00
<span v-if="isApproved">
2022-09-18 23:12:39 +00:00
{{ $t('components.audio.LibraryFollowButton.button.unfollow') }}
2022-09-15 23:01:21 +00:00
</span>
2022-11-26 23:16:46 +00:00
<span v-else-if="isPending">
2022-09-18 23:12:39 +00:00
{{ $t('components.audio.LibraryFollowButton.button.cancel') }}
2022-09-15 23:01:21 +00:00
</span>
2022-11-27 12:15:43 +00:00
<span v-else>
2022-09-18 23:12:39 +00:00
{{ $t('components.audio.LibraryFollowButton.button.follow') }}
2022-09-15 23:01:21 +00:00
</span>
</button>
</template>