add dialog for deleting smart collection

This commit is contained in:
Georges-Antoine Assi
2025-07-27 14:51:51 -04:00
parent b16003b96a
commit bd890b2f0e
6 changed files with 304 additions and 42 deletions

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import BaseGalleryAppBar from "@/components/Gallery/AppBar/Base.vue";
import CollectionInfoDrawer from "@/components/Gallery/AppBar/Collection/CollectionInfoDrawer.vue";
import SmartCollectionInfoDrawer from "@/components/Gallery/AppBar/Collection/SmartCollectionInfoDrawer.vue";
import RAvatar from "@/components/common/Collection/RAvatar.vue";
import storeNavigation from "@/stores/navigation";
import storeRoms from "@/stores/roms";
@@ -39,6 +40,7 @@ const activeCollection = computed(() => {
</base-gallery-app-bar>
<collection-info-drawer />
<smart-collection-info-drawer />
</template>
<style scoped>

View File

@@ -1,6 +1,7 @@
<script setup lang="ts">
import CollectionCard from "@/components/common/Collection/Card.vue";
import DeleteCollectionDialog from "@/components/common/Collection/Dialog/DeleteCollection.vue";
import DeleteSmartCollectionDialog from "@/components/common/Collection/Dialog/DeleteSmartCollection.vue";
import RSection from "@/components/common/RSection.vue";
import type { UpdatedCollection } from "@/services/api/collection";
import storeCollection from "@/stores/collections";
@@ -26,19 +27,6 @@ const romsStore = storeRoms();
const collectionsStore = storeCollection();
const { currentCollection } = storeToRefs(romsStore);
const navigationStore = storeNavigation();
// Get the currently active collection (any type)
const activeCollection = computed(() => currentCollection.value);
// Check if the active collection is editable (only regular collections are editable for now)
const isCollectionEditable = computed(() => {
return (
currentCollection.value &&
currentCollection.value.user__username === auth.user?.username &&
auth.scopes.includes("collections.write")
);
});
const imagePreviewUrl = ref<string | undefined>("");
const removeCover = ref(false);
const heartbeat = storeHeartbeat();
@@ -143,7 +131,7 @@ async function updateCollection() {
<template>
<v-navigation-drawer
v-if="activeCollection"
v-if="currentCollection"
mobile
floating
width="500"
@@ -158,7 +146,12 @@ async function updateCollection() {
<v-col style="max-width: 240px" cols="12">
<div class="text-center justify-center align-center">
<div class="position-absolute append-top-right mr-5">
<template v-if="isCollectionEditable">
<template
v-if="
currentCollection.user__username === auth.user?.username &&
auth.scopes.includes('collections.write')
"
>
<v-btn
v-if="!isEditable"
:loading="updating"
@@ -190,10 +183,10 @@ async function updateCollection() {
</template>
</div>
<collection-card
:key="activeCollection.updated_at"
:key="currentCollection.updated_at"
:show-title="false"
:with-link="false"
:collection="activeCollection"
:collection="currentCollection"
:src="imagePreviewUrl"
>
<template v-if="isEditable" #append-inner>
@@ -207,7 +200,7 @@ async function updateCollection() {
class="translucent-dark"
@click="
emitter?.emit('showSearchCoverDialog', {
term: activeCollection.name as string,
term: currentCollection.name as string,
aspectRatio: null,
})
"
@@ -248,23 +241,23 @@ async function updateCollection() {
<div v-if="!isEditable">
<div>
<span class="text-h5 font-weight-bold pl-0">{{
activeCollection.name
currentCollection.name
}}</span>
</div>
<div>
<span class="text-subtitle-2">{{
activeCollection.description
currentCollection.description
}}</span>
</div>
<v-chip
class="mt-4"
size="small"
:color="activeCollection.is_public ? 'primary' : ''"
:color="currentCollection.is_public ? 'primary' : ''"
><v-icon class="mr-1">{{
activeCollection.is_public ? "mdi-lock-open" : "mdi-lock"
currentCollection.is_public ? "mdi-lock-open" : "mdi-lock"
}}</v-icon
>{{
activeCollection.is_public
currentCollection.is_public
? t("collection.public")
: t("collection.private")
}}</v-chip
@@ -310,20 +303,17 @@ async function updateCollection() {
</v-col>
<v-col cols="12">
<v-card class="mt-4 bg-toplayer fill-width" elevation="0">
<v-card-text class="pa-4">
<template
v-for="(field, index) in collectionInfoFields"
:key="field.key"
>
<div :class="{ 'mt-4': index !== 0 }">
<v-card-text class="pa-4 d-flex">
<template v-for="field in collectionInfoFields" :key="field.key">
<div>
<v-chip size="small" class="mr-2 px-0" label>
<v-chip label>{{ field.label }}</v-chip
><span class="px-2">{{
activeCollection[
field.key as keyof typeof activeCollection
currentCollection[
field.key as keyof typeof currentCollection
]?.toString()
? activeCollection[
field.key as keyof typeof activeCollection
? currentCollection[
field.key as keyof typeof currentCollection
]
: "N/A"
}}</span>
@@ -337,7 +327,7 @@ async function updateCollection() {
<r-section
v-if="
auth.scopes.includes('collections.write') &&
activeCollection.user__username === auth.user?.username
currentCollection.user__username === auth.user?.username
"
icon="mdi-alert"
icon-color="red"
@@ -353,7 +343,7 @@ async function updateCollection() {
class="text-romm-red bg-toplayer ma-2"
variant="flat"
@click="
emitter?.emit('showDeleteCollectionDialog', activeCollection)
emitter?.emit('showDeleteCollectionDialog', currentCollection)
"
>
<v-icon class="text-romm-red mr-2">mdi-delete</v-icon>
@@ -365,6 +355,7 @@ async function updateCollection() {
</v-navigation-drawer>
<delete-collection-dialog />
<delete-smart-collection-dialog />
</template>
<style scoped>
.append-top-right {

View File

@@ -0,0 +1,273 @@
<script setup lang="ts">
import CollectionCard from "@/components/common/Collection/Card.vue";
import DeleteCollectionDialog from "@/components/common/Collection/Dialog/DeleteCollection.vue";
import RSection from "@/components/common/RSection.vue";
import storeCollection from "@/stores/collections";
import collectionApi from "@/services/api/collection";
import storeAuth from "@/stores/auth";
import storeNavigation from "@/stores/navigation";
import storeRoms from "@/stores/roms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useDisplay } from "vuetify";
// Props
const { t } = useI18n();
const { smAndDown } = useDisplay();
const emitter = inject<Emitter<Events>>("emitter");
const auth = storeAuth();
const romsStore = storeRoms();
const collectionsStore = storeCollection();
const { currentSmartCollection } = storeToRefs(romsStore);
const navigationStore = storeNavigation();
const { activeCollectionInfoDrawer } = storeToRefs(navigationStore);
const collectionInfoFields = [
{
key: "rom_count",
label: "Roms",
},
{
key: "user__username",
label: t("collection.owner"),
},
];
const updating = ref(false);
const isEditable = ref(false);
// Functions
function showEditable() {
isEditable.value = true;
}
function closeEditable() {
isEditable.value = false;
}
async function updateCollection() {
if (!currentSmartCollection.value) return;
updating.value = true;
isEditable.value = !isEditable.value;
await collectionApi
.updateSmartCollection({
smartCollection: currentSmartCollection.value,
})
.then(({ data }) => {
emitter?.emit("snackbarShow", {
msg: "Collection updated successfully",
icon: "mdi-check-bold",
color: "green",
});
currentSmartCollection.value = data;
collectionsStore.updateSmartCollection(data);
})
.catch((error) => {
emitter?.emit("snackbarShow", {
msg: `Failed to update collection: ${
error.response?.data?.msg || error.message
}`,
icon: "mdi-close-circle",
color: "red",
});
})
.finally(() => {
updating.value = false;
});
}
</script>
<template>
<v-navigation-drawer
v-if="currentSmartCollection"
mobile
floating
width="500"
v-model="activeCollectionInfoDrawer"
:class="{
'ml-2': activeCollectionInfoDrawer,
'drawer-mobile': smAndDown && activeCollectionInfoDrawer,
}"
class="bg-surface rounded mt-4 mb-2 pa-1 unset-height"
>
<v-row no-gutters class="justify-center align-center pa-2">
<v-col style="max-width: 240px" cols="12">
<div class="text-center justify-center align-center">
<div class="position-absolute append-top-right mr-5">
<template
v-if="
currentSmartCollection.user__username === auth.user?.username &&
auth.scopes.includes('collections.write')
"
>
<v-btn
v-if="!isEditable"
:loading="updating"
class="bg-toplayer"
@click="showEditable"
size="small"
>
<template #loader>
<v-progress-circular
color="primary"
:width="2"
:size="20"
indeterminate
/>
</template>
<v-icon>mdi-pencil</v-icon></v-btn
>
<template v-else>
<v-btn @click="closeEditable" size="small" class="bg-toplayer"
><v-icon color="romm-red">mdi-close</v-icon></v-btn
>
<v-btn
@click="updateCollection"
size="small"
class="bg-toplayer ml-1"
><v-icon color="romm-green">mdi-check</v-icon></v-btn
>
</template>
</template>
</div>
<collection-card
:key="currentSmartCollection.updated_at"
:show-title="false"
:with-link="false"
:collection="currentSmartCollection"
>
</collection-card>
</div>
</v-col>
<v-col cols="12">
<div class="text-center mt-4">
<div v-if="!isEditable">
<div>
<span class="text-h5 font-weight-bold pl-0">{{
currentSmartCollection.name
}}</span>
</div>
<div>
<span class="text-subtitle-2">{{
currentSmartCollection.description
}}</span>
</div>
<v-chip
class="mt-4"
size="small"
:color="currentSmartCollection.is_public ? 'primary' : ''"
><v-icon class="mr-1">{{
currentSmartCollection.is_public ? "mdi-lock-open" : "mdi-lock"
}}</v-icon
>{{
currentSmartCollection.is_public
? t("collection.public")
: t("collection.private")
}}</v-chip
>
</div>
<div class="text-center" v-else>
<v-text-field
class="mt-2"
v-model="currentSmartCollection.name"
:label="t('collection.name')"
variant="outlined"
required
density="compact"
hide-details
@keyup.enter="updateCollection"
/>
<v-text-field
class="mt-4"
v-model="currentSmartCollection.description"
:label="t('collection.description')"
variant="outlined"
required
density="compact"
hide-details
@keyup.enter="updateCollection"
/>
<v-switch
class="mt-2"
v-model="currentSmartCollection.is_public"
color="primary"
false-icon="mdi-lock"
true-icon="mdi-lock-open"
inset
hide-details
:label="
currentSmartCollection.is_public
? t('collection.public-desc')
: t('collection.private-desc')
"
/>
</div>
</div>
</v-col>
<v-col cols="12">
<v-card class="mt-4 bg-toplayer fill-width" elevation="0">
<v-card-text class="pa-4 d-flex">
<template v-for="field in collectionInfoFields" :key="field.key">
<div>
<v-chip size="small" class="mr-2 px-0" label>
<v-chip label>{{ field.label }}</v-chip
><span class="px-2">{{
currentSmartCollection[
field.key as keyof typeof currentSmartCollection
]?.toString()
? currentSmartCollection[
field.key as keyof typeof currentSmartCollection
]
: "N/A"
}}</span>
</v-chip>
</div>
</template>
</v-card-text>
</v-card>
</v-col>
</v-row>
<r-section
v-if="
auth.scopes.includes('collections.write') &&
currentSmartCollection.user__username === auth.user?.username
"
icon="mdi-alert"
icon-color="red"
:title="t('collection.danger-zone')"
elevation="0"
titleDivider
bgColor="bg-toplayer"
class="mx-2"
>
<template #content>
<div class="text-center">
<v-btn
class="text-romm-red bg-toplayer ma-2"
variant="flat"
@click="
emitter?.emit(
'showDeleteSmartCollectionDialog',
currentSmartCollection,
)
"
>
<v-icon class="text-romm-red mr-2">mdi-delete</v-icon>
{{ t("collection.delete-collection") }}
</v-btn>
</div>
</template>
</r-section>
</v-navigation-drawer>
<delete-collection-dialog />
</template>
<style scoped>
.append-top-right {
top: 0.3rem;
right: 0.3rem;
z-index: 1;
}
</style>

View File

@@ -4,7 +4,6 @@ import RSection from "@/components/common/RSection.vue";
import { type CollectionType } from "@/stores/collections";
import { views } from "@/utils";
import { isNull } from "lodash";
import { useI18n } from "vue-i18n";
import { onBeforeUnmount, onMounted, ref } from "vue";
const props = defineProps<{

View File

@@ -87,11 +87,6 @@ function closeDialog() {
t("collection.removing-smart-collection-2")
}}</span>
</v-row>
<v-row class="justify-center pa-2" no-gutters>
<v-alert type="warning" variant="tonal" class="ma-2" density="compact">
{{ t("collection.smart-collection-delete-warning") }}
</v-alert>
</v-row>
</template>
<template #append>
<v-row class="justify-center pa-2" no-gutters>

View File

@@ -12,5 +12,7 @@
"public-desc": "Pubilc (visible to everyone)",
"removing-collection-1": "Removing collection",
"removing-collection-2": "from RomM. Do you confirm?",
"search-collection": "Search collection"
"search-collection": "Search collection",
"removing-smart-collection-1": "Removing smart collection",
"removing-smart-collection-2": "from RomM. Do you confirm?"
}