koel/resources/assets/js/components/song/SongLikeButton.vue

29 lines
918 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-testid="like-btn">
2022-07-15 07:23:55 +00:00
<icon v-if="song.liked" :icon="faHeart" class="text-maroon" data-testid="btn-like-liked"/>
<icon v-else :icon="faEmptyHeart" data-testid="btn-like-unliked"/>
2022-04-15 14:24:30 +00:00
</button>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-07-15 07:23:55 +00:00
import { faHeart } from '@fortawesome/free-solid-svg-icons'
import { faHeart as faEmptyHeart } from '@fortawesome/free-regular-svg-icons'
2022-04-15 17:00:08 +00:00
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-06-10 10:47:46 +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 {
2022-07-15 07:23:55 +00:00
&:hover .fa-heart {
2022-04-15 14:24:30 +00:00
color: var(--color-maroon);
}
}
</style>