From 51bc201079f611eca4b957fed12361f3337e1af9 Mon Sep 17 00:00:00 2001 From: zurdi Date: Mon, 8 Jul 2024 13:56:33 +0200 Subject: [PATCH] added bulk add/remove from favourites --- .../src/components/Gallery/FabOverlay.vue | 85 ++++++++++++++++++- .../src/components/common/Game/FavBtn.vue | 2 +- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Gallery/FabOverlay.vue b/frontend/src/components/Gallery/FabOverlay.vue index 09576c49..3ac0e1f6 100644 --- a/frontend/src/components/Gallery/FabOverlay.vue +++ b/frontend/src/components/Gallery/FabOverlay.vue @@ -5,10 +5,14 @@ import storeAuth from "@/stores/auth"; import storeGalleryView from "@/stores/galleryView"; import storeHeartbeat from "@/stores/heartbeat"; import storeRoms from "@/stores/roms"; +import collectionApi, { + type UpdatedCollection, +} from "@/services/api/collection"; import storeScanning from "@/stores/scanning"; import type { Events } from "@/types/emitter"; import type { Emitter } from "mitt"; import { storeToRefs } from "pinia"; +import storeCollections, { type Collection } from "@/stores/collections"; import { inject, ref } from "vue"; import { useRoute } from "vue-router"; @@ -24,6 +28,8 @@ emitter?.on("openFabMenu", (open) => { }); const auth = storeAuth(); const scanningStore = storeScanning(); +const collectionsStore = storeCollections(); +const { favCollection } = storeToRefs(collectionsStore); const route = useRoute(); const heartbeat = storeHeartbeat(); @@ -61,6 +67,67 @@ function resetSelection() { emitter?.emit("openFabMenu", false); } +async function addToFavourites() { + if (!favCollection.value) return; + favCollection.value.roms = favCollection.value.roms.concat( + selectedRoms.value.map((r) => r.id) + ); + await collectionApi + .updateCollection({ collection: favCollection.value as Collection }) + .then(({ data }) => { + emitter?.emit("snackbarShow", { + msg: "Roms added to favourites successfully!", + icon: "mdi-check-bold", + color: "green", + timeout: 2000, + }); + }) + .catch((error) => { + console.log(error); + emitter?.emit("snackbarShow", { + msg: error.response.data.detail, + icon: "mdi-close-circle", + color: "red", + }); + return; + }) + .finally(() => { + emitter?.emit("showLoadingDialog", { loading: false, scrim: false }); + }); +} + +async function removeFromFavourites() { + if (!favCollection.value) return; + favCollection.value.roms = favCollection.value.roms.filter( + (value) => !selectedRoms.value.map((r) => r.id).includes(value) + ); + if (romsStore.currentCollection?.name.toLowerCase() == "favourites") { + romsStore.remove(selectedRoms.value); + } + await collectionApi + .updateCollection({ collection: favCollection.value as Collection }) + .then(() => { + emitter?.emit("snackbarShow", { + msg: "Roms removed from favourites successfully!", + icon: "mdi-check-bold", + color: "green", + timeout: 2000, + }); + }) + .catch((error) => { + console.log(error); + emitter?.emit("snackbarShow", { + msg: error.response.data.detail, + icon: "mdi-close-circle", + color: "red", + }); + return; + }) + .finally(() => { + emitter?.emit("showLoadingDialog", { loading: false, scrim: false }); + }); +} + function onDownload() { romsStore.selectedRoms.forEach((rom) => { romApi.downloadRom({ rom }); @@ -156,12 +223,28 @@ function onDownload() { key="5" color="terciary" elevation="8" + icon="mdi-star-outline" + size="default" + @click="removeFromFavourites" + /> + + (); -const collectionsStore = storeCollections(); const romsStore = storeRoms(); +const collectionsStore = storeCollections(); const { favCollection } = storeToRefs(collectionsStore); const emitter = inject>("emitter");