From dabd6bcf839cafdf49a15dfdd7577778d85d69bb Mon Sep 17 00:00:00 2001 From: Zurdi Date: Fri, 5 Jul 2024 18:45:36 +0200 Subject: [PATCH] added add to favourites from admin menu --- .../src/components/Details/Info/FileInfo.vue | 5 +- .../src/components/common/Game/AdminMenu.vue | 89 ++++++++++++++++++- .../src/components/common/Game/Card/Base.vue | 18 ++-- .../src/components/common/Game/FavBtn.vue | 14 ++- frontend/src/stores/collections.ts | 4 + 5 files changed, 109 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/Details/Info/FileInfo.vue b/frontend/src/components/Details/Info/FileInfo.vue index 0cb9b3f74..d57e5b646 100644 --- a/frontend/src/components/Details/Info/FileInfo.vue +++ b/frontend/src/components/Details/Info/FileInfo.vue @@ -157,7 +157,10 @@ watch( diff --git a/frontend/src/components/common/Game/AdminMenu.vue b/frontend/src/components/common/Game/AdminMenu.vue index bc1dca9bd..6647e3517 100644 --- a/frontend/src/components/common/Game/AdminMenu.vue +++ b/frontend/src/components/common/Game/AdminMenu.vue @@ -1,15 +1,88 @@ + + + {{ + `${collectionsStore.isFav(rom) ? "Remove from" : "Add to"} favourites` + }} + + { card.value.$el.addEventListener("contextmenu", (event: Event) => { @@ -163,7 +155,11 @@ onMounted(() => {
{ color="romm-accent-1" > {{ isFav() ? "mdi-star" : "mdi-star-outline" }} + >{{ + collectionsStore.isFav(rom) ? "mdi-star" : "mdi-star-outline" + }} diff --git a/frontend/src/components/common/Game/FavBtn.vue b/frontend/src/components/common/Game/FavBtn.vue index e0c47df0b..9aab5fd5c 100644 --- a/frontend/src/components/common/Game/FavBtn.vue +++ b/frontend/src/components/common/Game/FavBtn.vue @@ -18,10 +18,6 @@ const { favCollection } = storeToRefs(collectionsStore); const emitter = inject>("emitter"); // Functions -function isFav() { - return favCollection.value?.roms?.includes(props.rom.id); -} - async function switchFromFavourites() { if (!favCollection.value) { await collectionApi @@ -48,7 +44,7 @@ async function switchFromFavourites() { return; }); } - if (!isFav()) { + if (!collectionsStore.isFav(props.rom)) { favCollection.value?.roms.push(props.rom.id); } else { if (favCollection.value) { @@ -62,9 +58,9 @@ async function switchFromFavourites() { .updateCollection({ collection: favCollection.value as Collection }) .then(({ data }) => { emitter?.emit("snackbarShow", { - msg: `${props.rom.name} ${isFav() ? "added to" : "removed from"} ${ - favCollection.value?.name - } successfully!`, + msg: `${props.rom.name} ${ + collectionsStore.isFav(props.rom) ? "added to" : "removed from" + } ${favCollection.value?.name} successfully!`, icon: "mdi-check-bold", color: "green", timeout: 2000, @@ -94,7 +90,7 @@ async function switchFromFavourites() { variant="text" icon >{{ - isFav() ? "mdi-star" : "mdi-star-outline" + collectionsStore.isFav(rom) ? "mdi-star" : "mdi-star-outline" }} diff --git a/frontend/src/stores/collections.ts b/frontend/src/stores/collections.ts index e4f91dd09..205af8baf 100644 --- a/frontend/src/stores/collections.ts +++ b/frontend/src/stores/collections.ts @@ -1,6 +1,7 @@ import type { CollectionSchema } from "@/__generated__"; import { uniqBy } from "lodash"; import { defineStore } from "pinia"; +import type { SimpleRom } from "./roms"; export type Collection = CollectionSchema; @@ -54,5 +55,8 @@ export default defineStore("collections", { get(collectionId: number) { return this.allCollections.find((p) => p.id === collectionId); }, + isFav(rom: SimpleRom) { + return this.favCollection?.roms?.includes(rom.id); + }, }, });