mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
added add to favourites from admin menu
This commit is contained in:
@@ -157,7 +157,10 @@ watch(
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row
|
||||
v-if="rom.user_collections && rom.user_collections?.length > 0"
|
||||
v-if="
|
||||
rom.user_collections &&
|
||||
collectionsWithoutFavourites(rom.user_collections).length > 0
|
||||
"
|
||||
no-gutters
|
||||
class="align-center my-3"
|
||||
>
|
||||
|
||||
@@ -1,15 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import collectionApi, {
|
||||
type UpdatedCollection,
|
||||
} from "@/services/api/collection";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeCollections, { type Collection } from "@/stores/collections";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import storeRoms from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { inject } from "vue";
|
||||
|
||||
defineProps<{ rom: SimpleRom }>();
|
||||
// Props
|
||||
const props = defineProps<{ rom: SimpleRom }>();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const heartbeat = storeHeartbeat();
|
||||
const auth = storeAuth();
|
||||
const collectionsStore = storeCollections();
|
||||
const romsStore = storeRoms();
|
||||
const { favCollection } = storeToRefs(collectionsStore);
|
||||
|
||||
// Functions
|
||||
async function switchFromFavourites() {
|
||||
if (!favCollection.value) {
|
||||
await collectionApi
|
||||
.createCollection({
|
||||
collection: { name: "Favourites" } as UpdatedCollection,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
collectionsStore.add(data);
|
||||
favCollection.value = data;
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Collection ${data.name} created 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;
|
||||
});
|
||||
}
|
||||
if (!collectionsStore.isFav(props.rom)) {
|
||||
favCollection.value?.roms.push(props.rom.id);
|
||||
} else {
|
||||
if (favCollection.value) {
|
||||
favCollection.value.roms = favCollection.value.roms.filter(
|
||||
(id) => id !== props.rom.id
|
||||
);
|
||||
romsStore.remove([props.rom]);
|
||||
}
|
||||
}
|
||||
await collectionApi
|
||||
.updateCollection({ collection: favCollection.value as Collection })
|
||||
.then(({ data }) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `${props.rom.name} ${
|
||||
collectionsStore.isFav(props.rom) ? "added to" : "removed from"
|
||||
} ${favCollection.value?.name} 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 });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -41,6 +114,20 @@ const auth = storeAuth();
|
||||
</v-list-item>
|
||||
<v-divider />
|
||||
</template>
|
||||
<v-list-item
|
||||
v-if="auth.scopes.includes('collections.write')"
|
||||
class="py-4 pr-5"
|
||||
@click="switchFromFavourites"
|
||||
>
|
||||
<v-list-item-title class="d-flex">
|
||||
<v-icon
|
||||
:icon="collectionsStore.isFav(rom) ? 'mdi-star-outline' : 'mdi-star'"
|
||||
class="mr-2"
|
||||
/>{{
|
||||
`${collectionsStore.isFav(rom) ? "Remove from" : "Add to"} favourites`
|
||||
}}
|
||||
</v-list-item-title>
|
||||
</v-list-item>
|
||||
<v-list-item
|
||||
v-if="auth.scopes.includes('collections.write')"
|
||||
class="py-4 pr-5"
|
||||
|
||||
@@ -56,14 +56,6 @@ const card = ref();
|
||||
const theme = useTheme();
|
||||
const galleryViewStore = storeGalleryView();
|
||||
const collectionsStore = storeCollections();
|
||||
const { favCollection } = storeToRefs(collectionsStore);
|
||||
|
||||
// Functions
|
||||
function isFav() {
|
||||
if (romsStore.isSimpleRom(props.rom)) {
|
||||
return favCollection.value?.roms?.includes(props.rom.id);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
card.value.$el.addEventListener("contextmenu", (event: Event) => {
|
||||
@@ -163,7 +155,11 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="position-absolute append-inner">
|
||||
<v-btn
|
||||
v-if="isFav() && showFav"
|
||||
v-if="
|
||||
romsStore.isSimpleRom(rom) &&
|
||||
collectionsStore.isFav(rom) &&
|
||||
showFav
|
||||
"
|
||||
@click.stop=""
|
||||
class="label-fav"
|
||||
rouded="0"
|
||||
@@ -171,7 +167,9 @@ onMounted(() => {
|
||||
color="romm-accent-1"
|
||||
>
|
||||
<v-icon class="icon-fav" size="x-small"
|
||||
>{{ isFav() ? "mdi-star" : "mdi-star-outline" }}
|
||||
>{{
|
||||
collectionsStore.isFav(rom) ? "mdi-star" : "mdi-star-outline"
|
||||
}}
|
||||
</v-icon>
|
||||
</v-btn>
|
||||
<slot name="append-inner"> </slot>
|
||||
|
||||
@@ -18,10 +18,6 @@ const { favCollection } = storeToRefs(collectionsStore);
|
||||
const emitter = inject<Emitter<Events>>("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
|
||||
><v-icon color="romm-accent-1">{{
|
||||
isFav() ? "mdi-star" : "mdi-star-outline"
|
||||
collectionsStore.isFav(rom) ? "mdi-star" : "mdi-star-outline"
|
||||
}}</v-icon></v-btn
|
||||
>
|
||||
</template>
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user