handle favoriting in album page

+ fix fetching artist albums
+ create favoriteHandler composable
This commit is contained in:
geoffrey45
2022-12-28 09:07:55 +03:00
committed by Mungai Njoroge
parent a0cf95024c
commit d250928573
7 changed files with 69 additions and 51 deletions
+13 -4
View File
@@ -1,5 +1,11 @@
<template>
<button class="heart-button circular" @click="emit('handleFav')">
<button
class="heart-button circular"
@click="emit('handleFav')"
:class="{
is_fav: state,
}"
>
<HeartFillSvg v-if="state" />
<HeartSvg v-else />
</button>
@@ -19,15 +25,18 @@ const emit = defineEmits<{
</script>
<style lang="scss">
$bg: rgb(250, 33, 33);
.heart-button {
$bg: rgb(255, 184, 184);
background: $bg;
align-items: center;
padding: 0 1rem;
gap: $smaller;
border: solid 1px $bg;
background: transparent;
color: rgb(250, 33, 33);
&:hover {
background: $bg;
background: transparent;
}
}
</style>
+5 -19
View File
@@ -14,7 +14,7 @@
{{ index }}
</div>
<div class="heart-icon">
<HeartFillSvg v-if="fav" />
<HeartFillSvg v-if="is_fav" />
<HeartSvg v-else />
</div>
</div>
@@ -83,10 +83,10 @@ import OptionSvg from "@/assets/icons/more.svg";
import ArtistName from "./ArtistName.vue";
import useQueueStore from "@/stores/queue";
import { addFavorite, removeFavorite } from "@/composables/fetch/favorite";
import { favType } from "@/composables/enums";
import MasterFlag from "./MasterFlag.vue";
import favoriteHandler from "@/composables/favoriteHandler";
const imguri = paths.images.thumb.small;
const context_menu_showing = ref(false);
@@ -120,24 +120,10 @@ function isCurrentPlaying() {
return isCurrent() && queue.playing;
}
const fav = ref(props.track.is_favorite);
const is_fav = ref(props.track.is_favorite);
async function addToFav(trackhash: string) {
if (fav.value) {
const removed = await removeFavorite(favType.track, trackhash);
if (removed) {
fav.value = false;
}
return;
}
const added = await addFavorite(favType.track, trackhash);
if (added) {
fav.value = true;
}
function addToFav(trackhash: string) {
favoriteHandler(is_fav, favType.track, trackhash);
}
</script>