koel/resources/assets/js/components/song/like-button.vue

27 lines
773 B
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<button @click.stop="toggleLike" :title="title" class="text-secondary" data-test="like-btn">
<i class="fa fa-heart text-maroon" v-if="song.liked" data-test="btn-like-liked"></i>
<i class="fa fa-heart-o" data-test="btn-like-unliked" v-else></i>
</button>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
import { computed, toRefs } from 'vue'
2022-04-15 14:24:30 +00:00
import { favoriteStore } from '@/stores'
2022-04-15 17:00:08 +00:00
const props = defineProps<{ song: Song }>()
const { song } = toRefs(props)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const title = computed(() => `${song.value.liked ? 'Unlike' : 'Like'} ${song.value.title} by ${song.value.artist.name}`)
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
const toggleLike = () => favoriteStore.toggleOne(song.value)
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
button {
&:hover .fa-heart-o {
color: var(--color-maroon);
}
}
</style>