2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-09 13:04:24 +00:00
|
|
|
<button @click.stop="toggleLike" :title="title" class="text-secondary" data-testid="like-btn">
|
|
|
|
<i class="fa fa-heart text-maroon" v-if="song.liked" data-testid="btn-like-liked"></i>
|
|
|
|
<i class="fa fa-heart-o" data-testid="btn-like-unliked" v-else></i>
|
2022-04-15 14:24:30 +00:00
|
|
|
</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>
|