mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-16 17:51:17 +10:00
feat: collection deleting
This commit is contained in:
@ -1,16 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<ModalTemplate v-model="open">
|
<ModalTemplate v-model="open">
|
||||||
<template #default>
|
<template #default>
|
||||||
<DialogTitle as="h3" class="text-lg font-medium leading-6 text-white">
|
<div>
|
||||||
Create Collection
|
<DialogTitle as="h3" class="text-lg font-medium leading-6 text-white">
|
||||||
</DialogTitle>
|
Create collection
|
||||||
|
</DialogTitle>
|
||||||
|
<p class="mt-1 text-zinc-400 text-sm">
|
||||||
|
Collections can used to organise your games and find them more easily,
|
||||||
|
especially if you have a large library.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input
|
<form @submit.prevent="() => createCollection()">
|
||||||
type="text"
|
<input
|
||||||
v-model="collectionName"
|
type="text"
|
||||||
placeholder="Collection name"
|
v-model="collectionName"
|
||||||
class="block w-full rounded-md border-0 bg-zinc-800 py-1.5 text-white shadow-sm ring-1 ring-inset ring-zinc-700 placeholder:text-zinc-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
|
placeholder="Collection name"
|
||||||
/>
|
class="block w-full rounded-md border-0 bg-zinc-800 py-1.5 text-white shadow-sm ring-1 ring-inset ring-zinc-700 placeholder:text-zinc-400 focus:ring-2 focus:ring-inset focus:ring-blue-600 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
<button class="hidden" type="submit" />
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@ -1,88 +1,74 @@
|
|||||||
<template>
|
<template>
|
||||||
<ModalTemplate>
|
<ModalTemplate :modelValue="!!collection">
|
||||||
<template #default>
|
<template #default>
|
||||||
<DialogTitle as="h3" class="text-lg font-bold font-display text-zinc-100">
|
<div>
|
||||||
Delete Collection
|
<DialogTitle
|
||||||
</DialogTitle>
|
as="h3"
|
||||||
<div class="mt-2">
|
class="text-lg font-bold font-display text-zinc-100"
|
||||||
<p class="text-sm text-zinc-400">
|
>
|
||||||
Are you sure you want to delete "{{ collection?.name }}"? This action
|
Delete Collection
|
||||||
cannot be undone.
|
</DialogTitle>
|
||||||
|
<p class="mt-1 text-sm text-zinc-400">
|
||||||
|
Are you sure you want to delete "{{ collection?.name }}"?
|
||||||
|
</p>
|
||||||
|
<p class="mt-2 text-sm font-bold text-red-500">
|
||||||
|
This action cannot be undone.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #buttons="{ close }">
|
<template #buttons>
|
||||||
<button
|
|
||||||
@click="() => close()"
|
|
||||||
class="inline-flex items-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold font-display text-white hover:bg-zinc-700"
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
:loading="deleteLoading"
|
:loading="deleteLoading"
|
||||||
@click="() => handleDelete()"
|
@click="() => deleteCollection()"
|
||||||
class="bg-red-600 text-white hover:bg-red-500"
|
class="bg-red-600 text-white hover:bg-red-500"
|
||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
|
<button
|
||||||
|
@click="() => (collection = undefined)"
|
||||||
|
class="inline-flex items-center rounded-md bg-zinc-800 px-3 py-2 text-sm font-semibold font-display text-white hover:bg-zinc-700"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
</template>
|
</template>
|
||||||
</ModalTemplate>
|
</ModalTemplate>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { Collection } from "@prisma/client";
|
import type { Collection } from "@prisma/client";
|
||||||
import {
|
import { DialogTitle } from "@headlessui/vue";
|
||||||
TransitionRoot,
|
|
||||||
TransitionChild,
|
|
||||||
Dialog,
|
|
||||||
DialogPanel,
|
|
||||||
DialogTitle,
|
|
||||||
} from "@headlessui/vue";
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const collection = defineModel<Collection | undefined>();
|
||||||
collection: Collection | null;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
deleted: [collectionId: string];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const open = defineModel<boolean>();
|
|
||||||
const deleteLoading = ref(false);
|
const deleteLoading = ref(false);
|
||||||
|
|
||||||
const collections = await useCollections();
|
const collections = await useCollections();
|
||||||
|
|
||||||
const handleDelete = async () => {
|
async function deleteCollection() {
|
||||||
if (!props.collection) return;
|
|
||||||
|
|
||||||
deleteLoading.value = true;
|
|
||||||
try {
|
try {
|
||||||
await $fetch(`/api/v1/collection/${props.collection.id}`, {
|
if (!collection.value) return;
|
||||||
|
|
||||||
|
deleteLoading.value = true;
|
||||||
|
await $fetch(`/api/v1/collection/${collection.value.id}`, {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
|
const index = collections.value.findIndex(
|
||||||
collections.value.splice(
|
(e) => e.id == collection.value?.id
|
||||||
collections.value.findIndex((e) => e.id === props.collection?.id),
|
|
||||||
1
|
|
||||||
);
|
);
|
||||||
|
collections.value.splice(index, 1);
|
||||||
|
|
||||||
open.value = false;
|
collection.value = undefined;
|
||||||
emit("deleted", props.collection.id);
|
} catch (e: any) {
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to delete collection:", error);
|
|
||||||
|
|
||||||
const err = error as { statusMessage?: string };
|
|
||||||
createModal(
|
createModal(
|
||||||
ModalType.Notification,
|
ModalType.Notification,
|
||||||
{
|
{
|
||||||
title: "Failed to create collection",
|
title: "Failed to add game to library",
|
||||||
description: `Drop couldn't create your collection: ${err?.statusMessage}`,
|
description: `Drop couldn't add this game to your library: ${e?.statusMessage}`,
|
||||||
},
|
},
|
||||||
(_, c) => c()
|
(_, c) => c()
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
deleteLoading.value = false;
|
deleteLoading.value = false;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -35,8 +35,7 @@
|
|||||||
|
|
||||||
<!-- Delete button (only show for non-default collections) -->
|
<!-- Delete button (only show for non-default collections) -->
|
||||||
<button
|
<button
|
||||||
v-if="!collection.isDefault"
|
@click="() => (currentlyDeleting = collection)"
|
||||||
@click=""
|
|
||||||
class="px-3 ml-[2px] bg-zinc-800/50 hover:bg-zinc-800"
|
class="px-3 ml-[2px] bg-zinc-800/50 hover:bg-zinc-800"
|
||||||
>
|
>
|
||||||
<TrashIcon class="h-5 w-5 text-zinc-400 hover:text-red-400" />
|
<TrashIcon class="h-5 w-5 text-zinc-400 hover:text-red-400" />
|
||||||
@ -57,7 +56,9 @@
|
|||||||
Create Collection
|
Create Collection
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<p class="transition mt-1 text-sm text-zinc-500 group-hover:text-zinc-400">
|
<p
|
||||||
|
class="transition mt-1 text-sm text-zinc-500 group-hover:text-zinc-400"
|
||||||
|
>
|
||||||
Add a new collection to organize your games
|
Add a new collection to organize your games
|
||||||
</p>
|
</p>
|
||||||
</button>
|
</button>
|
||||||
@ -66,6 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CreateCollectionModal v-model="collectionCreateOpen" />
|
<CreateCollectionModal v-model="collectionCreateOpen" />
|
||||||
|
<DeleteCollectionModal v-model="currentlyDeleting" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@ -75,18 +77,19 @@ import {
|
|||||||
TrashIcon,
|
TrashIcon,
|
||||||
ArrowLeftIcon,
|
ArrowLeftIcon,
|
||||||
} from "@heroicons/vue/20/solid";
|
} from "@heroicons/vue/20/solid";
|
||||||
import { type Game, type GameVersion } from "@prisma/client";
|
import { type Collection, type Game, type GameVersion } from "@prisma/client";
|
||||||
import { PlusIcon } from "@heroicons/vue/20/solid";
|
import { PlusIcon } from "@heroicons/vue/20/solid";
|
||||||
|
|
||||||
const headers = useRequestHeaders(["cookie"]);
|
const headers = useRequestHeaders(["cookie"]);
|
||||||
const { data: gamesData } = await useFetch<
|
const { data: gamesData } = await useFetch<
|
||||||
(Game & { versions: GameVersion[] })[]
|
(Game & { versions: GameVersion[] })[]
|
||||||
>("/api/v1/store/recent", { headers });
|
>("/api/v1/store/recent", { headers });
|
||||||
const games = ref(gamesData.value || []);
|
|
||||||
|
|
||||||
const collections = await useCollections();
|
const collections = await useCollections();
|
||||||
const collectionCreateOpen = ref(false);
|
const collectionCreateOpen = ref(false);
|
||||||
|
|
||||||
|
const currentlyDeleting = ref<Collection | undefined>();
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
title: "Home",
|
title: "Home",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user