mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-10 04:22:09 +10:00
feat: refactored into separate metadata and library pages
This commit is contained in:
@ -1,546 +1,88 @@
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<template>
|
||||
<div>
|
||||
<div
|
||||
v-if="game && unimportedVersions !== undefined"
|
||||
class="grow flex flex-col gap-y-8"
|
||||
<!-- import games button -->
|
||||
<NuxtLink
|
||||
v-if="unimportedVersions !== undefined"
|
||||
:href="
|
||||
unimportedVersions.length > 0 ? `/admin/library/${game.id}/import` : ''
|
||||
"
|
||||
type="button"
|
||||
:class="[
|
||||
unimportedVersions.length > 0
|
||||
? 'bg-blue-600 hover:bg-blue-700'
|
||||
: 'bg-blue-800/50',
|
||||
'inline-flex w-fit items-center gap-x-2 rounded-md px-3 py-1 text-sm font-semibold font-display text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600',
|
||||
]"
|
||||
>
|
||||
<div class="grow w-full h-full lg:pr-[30vw] px-6 py-4 flex flex-col">
|
||||
<div
|
||||
class="flex flex-col lg:flex-row lg:justify-between items-start lg:items-center gap-2"
|
||||
>
|
||||
<div class="inline-flex items-center gap-4">
|
||||
<img :src="useObject(game.mIconObjectId)" class="size-20" />
|
||||
<div>
|
||||
<h1 class="text-5xl font-bold font-display text-zinc-100">
|
||||
{{ game.mName }}
|
||||
</h1>
|
||||
<p class="mt-1 text-lg text-zinc-400">
|
||||
{{ game.mShortDescription }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex gap-x-3 items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showEditCoreMetadata = true)"
|
||||
{{
|
||||
unimportedVersions.length > 0
|
||||
? "Import version"
|
||||
: "No versions to import"
|
||||
}}
|
||||
</NuxtLink>
|
||||
|
||||
<!-- version priority -->
|
||||
<div>
|
||||
<div class="border-b border-zinc-800 pb-3">
|
||||
<div class="flex flex-wrap items-center justify-between sm:flex-nowrap">
|
||||
<h3
|
||||
class="text-base font-semibold font-display leading-6 text-zinc-100"
|
||||
>
|
||||
Edit <PencilIcon class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- image carousel pick -->
|
||||
<div class="border-b border-zinc-700">
|
||||
<div class="border-b border-zinc-700 py-4">
|
||||
<div
|
||||
class="-ml-4 -mt-4 flex flex-wrap items-center justify-between sm:flex-nowrap"
|
||||
>
|
||||
<div class="ml-4 mt-4">
|
||||
<h3 class="text-base font-semibold text-zinc-100">
|
||||
Image Carousel
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-zinc-400 max-w-lg">
|
||||
Customise what images and what order are shown on the store
|
||||
page.
|
||||
</p>
|
||||
</div>
|
||||
<div class="ml-4 mt-4 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showAddCarouselModal = true)"
|
||||
>
|
||||
Add from image library
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="game.mImageCarouselObjectIds.length == 0"
|
||||
class="text-zinc-400 text-center py-8"
|
||||
>
|
||||
No images added to the carousel yet.
|
||||
</div>
|
||||
|
||||
<draggable
|
||||
v-else
|
||||
:list="game.mImageCarouselObjectIds"
|
||||
class="w-full flex flex-row gap-x-4 overflow-x-auto my-2 py-4"
|
||||
@update="() => updateImageCarousel()"
|
||||
>
|
||||
<template #item="{ element }: { element: string }">
|
||||
<div class="relative group min-w-fit">
|
||||
<img :src="useObject(element)" class="h-48 w-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => removeImageFromCarousel(element)"
|
||||
>
|
||||
Remove image
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</div>
|
||||
|
||||
<!-- description editor -->
|
||||
<div
|
||||
class="mt-4 grow flex flex-col w-full space-y-4 border border-zinc-800 rounded overflow-hidden p-2"
|
||||
>
|
||||
<!-- toolbar -->
|
||||
<div
|
||||
class="h-8 bg-zinc-800 rounded inline-flex gap-x-4 items-center justify-start p-2"
|
||||
>
|
||||
<div>
|
||||
<CheckIcon
|
||||
v-if="descriptionSaving == 0"
|
||||
class="size-5 text-zinc-100"
|
||||
/>
|
||||
<div v-else-if="descriptionSaving == 1">
|
||||
<PencilIcon class="animate-pulse size-5 text-zinc-100" />
|
||||
</div>
|
||||
<div v-else-if="descriptionSaving == 2" role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-5 h-5 text-transparent animate-spin fill-white"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button @click="() => (showAddImageDescriptionModal = true)">
|
||||
<PhotoIcon
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="block lg:hidden"
|
||||
@click="
|
||||
() => (mobileShowFinalDescription = !mobileShowFinalDescription)
|
||||
"
|
||||
>
|
||||
<DocumentIcon
|
||||
v-if="!mobileShowFinalDescription"
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
<PencilIcon
|
||||
v-else
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<!-- edit area -->
|
||||
<div class="grid lg:grid-cols-2 lg:gap-x-8 grow">
|
||||
<!-- editing box -->
|
||||
<div
|
||||
:class="[
|
||||
mobileShowFinalDescription ? 'hidden' : 'block',
|
||||
'lg:block',
|
||||
]"
|
||||
>
|
||||
<textarea
|
||||
ref="descriptionEditor"
|
||||
v-model="game.mDescription"
|
||||
class="grow h-full w-full bg-zinc-950/30 text-zinc-100 border-zinc-900 rounded"
|
||||
/>
|
||||
</div>
|
||||
<!-- result box -->
|
||||
<div
|
||||
:class="[
|
||||
mobileShowFinalDescription ? 'block' : 'hidden',
|
||||
'lg:block prose prose-invert prose-blue bg-zinc-950/30 rounded px-4 py-3',
|
||||
]"
|
||||
v-html="descriptionHTML"
|
||||
/>
|
||||
</div>
|
||||
Version priority
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="lg:overflow-y-auto lg:border-l lg:border-zinc-800 lg:fixed lg:inset-y-0 lg:z-50 lg:w-[30vw] flex flex-col lg:right-0 gap-y-8 px-6 py-4"
|
||||
|
||||
<div class="mt-4 text-center w-full text-sm text-zinc-600">lowest</div>
|
||||
<draggable
|
||||
:list="game.versions"
|
||||
handle=".handle"
|
||||
class="mt-2 space-y-4"
|
||||
@update="() => updateVersionOrder()"
|
||||
>
|
||||
<!-- toolbar -->
|
||||
<div class="inline-flex justify-end items-stretch gap-x-4">
|
||||
<!-- import games button -->
|
||||
<NuxtLink
|
||||
:href="
|
||||
unimportedVersions.length > 0
|
||||
? `/admin/library/${game.id}/import`
|
||||
: ''
|
||||
"
|
||||
type="button"
|
||||
:class="[
|
||||
unimportedVersions.length > 0
|
||||
? 'bg-blue-600 hover:bg-blue-700'
|
||||
: 'bg-blue-800/50',
|
||||
'inline-flex w-fit items-center gap-x-2 rounded-md px-3 py-1 text-sm font-semibold font-display text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600',
|
||||
]"
|
||||
>
|
||||
{{
|
||||
unimportedVersions.length > 0
|
||||
? "Import version"
|
||||
: "No versions to import"
|
||||
}}
|
||||
</NuxtLink>
|
||||
<!-- open in store button -->
|
||||
<NuxtLink
|
||||
:href="`/store/${game.id}`"
|
||||
type="button"
|
||||
class="inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open in Store
|
||||
<ArrowTopRightOnSquareIcon
|
||||
class="-mr-0.5 h-7 w-7 p-1"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- image library -->
|
||||
<div>
|
||||
<div class="border-b border-zinc-800 pb-3">
|
||||
<div
|
||||
class="flex flex-wrap items-center justify-between sm:flex-nowrap gap-4"
|
||||
>
|
||||
<div>
|
||||
<h3
|
||||
class="text-base font-semibold font-display leading-6 text-zinc-100"
|
||||
>
|
||||
Image library
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-zinc-400 max-w-lg">
|
||||
Please note all images uploaded are accessible to all users
|
||||
through browser dev-tools.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showUploadModal = true)"
|
||||
>
|
||||
Upload
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-2 grid-flow-dense gap-8">
|
||||
<div
|
||||
v-for="(image, imageIdx) in game.mImageLibraryObjectIds"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
v-if="image !== game.mBannerObjectId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => updateBannerImage(image)"
|
||||
>
|
||||
Set as banner
|
||||
</button>
|
||||
<button
|
||||
v-if="image !== game.mCoverObjectId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => updateCoverImage(image)"
|
||||
>
|
||||
Set as cover
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-red-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
|
||||
@click="() => deleteImage(image)"
|
||||
>
|
||||
Delete image
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
image === game.mBannerObjectId ||
|
||||
image === game.mCoverObjectId
|
||||
"
|
||||
class="absolute bottom-0 left-0 bg-zinc-950/75 text-zinc-100 text-sm font-semibold px-2 py-1 rounded-tr"
|
||||
>
|
||||
current
|
||||
{{
|
||||
[
|
||||
image === game.mBannerObjectId ? "banner" : undefined,
|
||||
image === game.mCoverObjectId ? "cover" : undefined,
|
||||
]
|
||||
.filter((e) => e)
|
||||
.join(" & ")
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- version priority -->
|
||||
<div>
|
||||
<div class="border-b border-zinc-800 pb-3">
|
||||
<div
|
||||
class="flex flex-wrap items-center justify-between sm:flex-nowrap"
|
||||
>
|
||||
<h3
|
||||
class="text-base font-semibold font-display leading-6 text-zinc-100"
|
||||
>
|
||||
Version priority
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 text-center w-full text-sm text-zinc-600">
|
||||
lowest
|
||||
</div>
|
||||
<draggable
|
||||
:list="game.versions"
|
||||
handle=".handle"
|
||||
class="mt-2 space-y-4"
|
||||
@update="() => updateVersionOrder()"
|
||||
>
|
||||
<template #item="{ element: item }: { element: GameVersion }">
|
||||
<div
|
||||
class="w-full inline-flex items-center px-4 py-2 bg-zinc-800 rounded justify-between"
|
||||
>
|
||||
<div class="text-zinc-100 font-semibold">
|
||||
{{ item.versionName }}
|
||||
</div>
|
||||
<div class="text-zinc-400">
|
||||
{{ item.delta ? "Upgrade mode" : "" }}
|
||||
</div>
|
||||
<div class="inline-flex items-center gap-x-2">
|
||||
<component
|
||||
:is="PLATFORM_ICONS[item.platform]"
|
||||
class="size-6 text-blue-600"
|
||||
/>
|
||||
<Bars3Icon class="cursor-move w-6 h-6 text-zinc-400 handle" />
|
||||
<button @click="() => deleteVersion(item.versionName)">
|
||||
<TrashIcon class="w-5 h-5 text-red-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
<template #item="{ element: item }: { element: GameVersion }">
|
||||
<div
|
||||
v-if="game.versions.length == 0"
|
||||
class="text-center font-bold text-zinc-400 my-3"
|
||||
class="w-full inline-flex items-center px-4 py-2 bg-zinc-800 rounded justify-between"
|
||||
>
|
||||
no versions added
|
||||
</div>
|
||||
<div class="mt-2 text-center w-full text-sm text-zinc-600">
|
||||
highest
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<UploadFileDialog
|
||||
v-model="showUploadModal"
|
||||
:options="{ id: game.id }"
|
||||
accept="image/*"
|
||||
endpoint="/api/v1/admin/game/image"
|
||||
@upload="(result: Game) => uploadAfterImageUpload(result)"
|
||||
/>
|
||||
<ModalTemplate v-model="showAddCarouselModal">
|
||||
<template #default>
|
||||
<div class="grid grid-cols-2 grid-flow-dense gap-4">
|
||||
<div
|
||||
v-for="(image, imageIdx) in validAddCarouselImages"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => addImageToCarousel(image)"
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
<div class="text-zinc-100 font-semibold">
|
||||
{{ item.versionName }}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="validAddCarouselImages.length == 0"
|
||||
class="text-zinc-400 col-span-2"
|
||||
>
|
||||
No images to add.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showAddCarouselModal = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
<ModalTemplate v-model="showAddImageDescriptionModal">
|
||||
<template #default>
|
||||
<div class="grid grid-cols-2 grid-flow-dense gap-4">
|
||||
<div
|
||||
v-for="(image, imageIdx) in game.mImageLibraryObjectIds"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => insertImageAtCursor(image)"
|
||||
>
|
||||
Insert
|
||||
</button>
|
||||
<div class="text-zinc-400">
|
||||
{{ item.delta ? "Upgrade mode" : "" }}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="game.mImageLibraryObjectIds.length == 0"
|
||||
class="text-zinc-400 col-span-2"
|
||||
>
|
||||
No images to add.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showAddCarouselModal = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
<ModalTemplate v-model="showEditCoreMetadata">
|
||||
<template #default>
|
||||
<div class="flex flex-col lg:flex-row gap-6">
|
||||
<!-- icon upload div -->
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<img :src="coreMetadataIconUrl" class="size-24 aspect-square" />
|
||||
<label for="file-upload">
|
||||
<span
|
||||
type="button"
|
||||
class="cursor-pointer relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Upload
|
||||
</span>
|
||||
<input
|
||||
id="file-upload"
|
||||
accept="image/*"
|
||||
class="hidden"
|
||||
type="file"
|
||||
@change="(e) => coreMetadataUploadFiles(e as any)"
|
||||
<div class="inline-flex items-center gap-x-2">
|
||||
<component
|
||||
:is="PLATFORM_ICONS[item.platform]"
|
||||
class="size-6 text-blue-600"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<!-- edit title -->
|
||||
<div class="flex flex-col gap-y-4 grow">
|
||||
<div>
|
||||
<label
|
||||
for="name"
|
||||
class="block text-sm/6 font-medium text-zinc-100"
|
||||
>Game Name</label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="name"
|
||||
v-model="coreMetadataName"
|
||||
type="text"
|
||||
name="name"
|
||||
class="block w-full rounded-md bg-zinc-800 px-3 py-1.5 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-zinc-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
for="description"
|
||||
class="block text-sm/6 font-medium text-zinc-100"
|
||||
>Game Description</label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="description"
|
||||
v-model="coreMetadataDescription"
|
||||
type="text"
|
||||
name="description"
|
||||
class="block w-full rounded-md bg-zinc-800 px-3 py-1.5 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-zinc-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6"
|
||||
/>
|
||||
</div>
|
||||
<Bars3Icon class="cursor-move w-6 h-6 text-zinc-400 handle" />
|
||||
<button @click="() => deleteVersion(item.versionName)">
|
||||
<TrashIcon class="w-5 h-5 text-red-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<LoadingButton
|
||||
type="button"
|
||||
:loading="coreMetadataLoading"
|
||||
:class="['inline-flex w-full shadow-sm sm:ml-3 sm:w-auto']"
|
||||
@click="() => coreMetadataUpdate_wrapper()"
|
||||
>
|
||||
Save
|
||||
</LoadingButton>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showEditCoreMetadata = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
</template>
|
||||
</draggable>
|
||||
<div
|
||||
v-if="game.versions.length == 0"
|
||||
class="text-center font-bold text-zinc-400 my-3"
|
||||
>
|
||||
no versions added
|
||||
</div>
|
||||
<div class="mt-2 text-center w-full text-sm text-zinc-600">highest</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Bars3Icon, TrashIcon } from "@heroicons/vue/16/solid";
|
||||
import type { Game, GameVersion } from "~/prisma/client";
|
||||
import { micromark } from "micromark";
|
||||
import {
|
||||
ArrowTopRightOnSquareIcon,
|
||||
CheckIcon,
|
||||
DocumentIcon,
|
||||
PencilIcon,
|
||||
PhotoIcon,
|
||||
} from "@heroicons/vue/24/solid";
|
||||
import type { GameVersion } from "~/prisma/client";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const showUploadModal = ref(false);
|
||||
const showAddCarouselModal = ref(false);
|
||||
const showAddImageDescriptionModal = ref(false);
|
||||
const showEditCoreMetadata = ref(false);
|
||||
const mobileShowFinalDescription = ref(true);
|
||||
// TODO implement UI for this
|
||||
|
||||
const route = useRoute();
|
||||
const gameId = route.params.id.toString();
|
||||
@ -549,158 +91,22 @@ const { game: rawGame, unimportedVersions } = await $dropFetch(
|
||||
);
|
||||
const game = ref(rawGame);
|
||||
|
||||
const coreMetadataName = ref(game.value.mName);
|
||||
const coreMetadataDescription = ref(game.value.mShortDescription);
|
||||
const coreMetadataIconUrl = ref(useObject(game.value.mIconObjectId));
|
||||
const coreMetadataIconFileUpload = ref<FileList | undefined>();
|
||||
const coreMetadataLoading = ref(false);
|
||||
|
||||
function coreMetadataUploadFiles(e: InputEvent) {
|
||||
if (coreMetadataIconUrl.value.startsWith("blob")) {
|
||||
console.log("freed object URL");
|
||||
URL.revokeObjectURL(coreMetadataIconUrl.value);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
coreMetadataIconFileUpload.value = (e.target as any)?.files;
|
||||
const file = coreMetadataIconFileUpload.value?.item(0);
|
||||
if (!file) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to upload file",
|
||||
description: "Drop couldn't upload this file.",
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
coreMetadataIconUrl.value = objectUrl;
|
||||
}
|
||||
async function coreMetadataUpdate() {
|
||||
const formData = new FormData();
|
||||
|
||||
const newIcon = coreMetadataIconFileUpload.value?.item(0);
|
||||
if (newIcon) {
|
||||
formData.append("icon", newIcon);
|
||||
}
|
||||
|
||||
formData.append("id", game.value.id);
|
||||
formData.append("name", coreMetadataName.value);
|
||||
formData.append("description", coreMetadataDescription.value);
|
||||
|
||||
const result = await $dropFetch(`/api/v1/admin/game/metadata`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function coreMetadataUpdate_wrapper() {
|
||||
coreMetadataLoading.value = true;
|
||||
coreMetadataUpdate()
|
||||
.catch((e) => {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to update metadata",
|
||||
description: `Drop failed to update the game's metadata: ${
|
||||
e?.statusMessage || "An unknown error occurred. "
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
})
|
||||
.then((newGame) => {
|
||||
if (!newGame) return;
|
||||
Object.assign(game.value, newGame);
|
||||
})
|
||||
.finally(() => {
|
||||
coreMetadataLoading.value = false;
|
||||
showEditCoreMetadata.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
const descriptionHTML = computed(() =>
|
||||
micromark(game.value?.mDescription ?? ""),
|
||||
);
|
||||
const descriptionEditor = ref<HTMLTextAreaElement | undefined>();
|
||||
// 0 is not loading
|
||||
// 1 is waiting for stop
|
||||
// 2 is loading
|
||||
const descriptionSaving = ref<number>(0);
|
||||
|
||||
let savingTimeout: undefined | NodeJS.Timeout;
|
||||
|
||||
watch(descriptionHTML, (_v) => {
|
||||
console.log(game.value.mDescription);
|
||||
descriptionSaving.value = 1;
|
||||
if (savingTimeout) clearTimeout(savingTimeout);
|
||||
savingTimeout = setTimeout(async () => {
|
||||
try {
|
||||
descriptionSaving.value = 2;
|
||||
await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mDescription: game.value.mDescription,
|
||||
},
|
||||
});
|
||||
descriptionSaving.value = 0;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to update game description",
|
||||
description: `Drop failed to update the game description: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred."
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
const validAddCarouselImages = computed(() =>
|
||||
game.value.mImageLibraryObjectIds.filter(
|
||||
(e) => !game.value.mImageCarouselObjectIds.includes(e),
|
||||
),
|
||||
);
|
||||
|
||||
function insertImageAtCursor(id: string) {
|
||||
showAddImageDescriptionModal.value = false;
|
||||
if (!descriptionEditor.value || !game.value) return;
|
||||
const insertPosition = descriptionEditor.value.selectionStart;
|
||||
const text = ``;
|
||||
game.value.mDescription = `${game.value.mDescription.slice(
|
||||
0,
|
||||
insertPosition,
|
||||
)}${text}${game.value.mDescription.slice(insertPosition)}`;
|
||||
}
|
||||
|
||||
async function updateBannerImage(id: string) {
|
||||
async function updateVersionOrder() {
|
||||
try {
|
||||
if (game.value.mBannerObjectId == id) return;
|
||||
const { mBannerObjectId } = await $dropFetch("/api/v1/admin/game", {
|
||||
const newVersions = await $dropFetch("/api/v1/admin/game/version", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mBannerId: id,
|
||||
versions: game.value.versions.map((e) => e.versionName),
|
||||
},
|
||||
});
|
||||
game.value.mBannerObjectId = mBannerObjectId;
|
||||
game.value.versions = newVersions;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the banner image",
|
||||
description: `Drop encountered an error while updating the banner image: ${
|
||||
title: "There an error while updating the version order",
|
||||
description: `Drop encountered an error while updating the version: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
@ -711,68 +117,6 @@ async function updateBannerImage(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateCoverImage(id: string) {
|
||||
try {
|
||||
if (game.value.mCoverObjectId == id) return;
|
||||
const { mCoverObjectId } = await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mCoverId: id,
|
||||
},
|
||||
});
|
||||
game.value.mCoverObjectId = mCoverObjectId;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the cover image",
|
||||
description: `Drop encountered an error while updating the cover image: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteImage(id: string) {
|
||||
try {
|
||||
const { mBannerObjectId, mImageLibraryObjectIds } = await $dropFetch(
|
||||
"/api/v1/admin/game/image",
|
||||
{
|
||||
method: "DELETE",
|
||||
body: {
|
||||
gameId: game.value.id,
|
||||
imageId: id,
|
||||
},
|
||||
},
|
||||
);
|
||||
game.value.mImageLibraryObjectIds = mImageLibraryObjectIds;
|
||||
game.value.mBannerObjectId = mBannerObjectId;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while deleting the image",
|
||||
description: `Drop encountered an error while deleting the image: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadAfterImageUpload(result: Game) {
|
||||
if (!game.value) return;
|
||||
game.value.mImageLibraryObjectIds = result.mImageLibraryObjectIds;
|
||||
}
|
||||
|
||||
async function deleteVersion(versionName: string) {
|
||||
try {
|
||||
await $dropFetch("/api/v1/admin/game/version", {
|
||||
@ -801,69 +145,4 @@ async function deleteVersion(versionName: string) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateVersionOrder() {
|
||||
try {
|
||||
const newVersions = await $dropFetch("/api/v1/admin/game/version", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
versions: game.value.versions.map((e) => e.versionName),
|
||||
},
|
||||
});
|
||||
game.value.versions = newVersions;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the version order",
|
||||
description: `Drop encountered an error while updating the version: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function addImageToCarousel(id: string) {
|
||||
showAddCarouselModal.value = false;
|
||||
game.value.mImageCarouselObjectIds.push(id);
|
||||
updateImageCarousel();
|
||||
}
|
||||
|
||||
function removeImageFromCarousel(id: string) {
|
||||
const imageIndex = game.value.mImageCarouselObjectIds.findIndex(
|
||||
(e) => e == id,
|
||||
);
|
||||
game.value.mImageCarouselObjectIds.splice(imageIndex, 1);
|
||||
updateImageCarousel();
|
||||
}
|
||||
|
||||
async function updateImageCarousel() {
|
||||
try {
|
||||
await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mImageCarousel: game.value.mImageCarouselObjectIds,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the image carousel",
|
||||
description: `Drop encountered an error while updating image carousel: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -85,15 +85,21 @@
|
||||
</dd>
|
||||
<dt class="sr-only">Metadata provider</dt>
|
||||
</dl>
|
||||
<div class="inline-flex gap-x-2 items-center">
|
||||
<div class="mt-4 flex flex-col gap-y-1">
|
||||
<NuxtLink
|
||||
:href="`/admin/library/${game.id}`"
|
||||
class="mt-2 w-fit rounded-md bg-blue-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
class="w-fit rounded-md bg-blue-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Edit →
|
||||
Open with Library →
|
||||
</NuxtLink>
|
||||
<NuxtLink
|
||||
:href="`/admin/metadata/games/${game.id}`"
|
||||
class="w-fit rounded-md bg-zinc-800 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open with Metadata →
|
||||
</NuxtLink>
|
||||
<button
|
||||
class="mt-2 w-fit rounded-md bg-red-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
|
||||
class="w-fit rounded-md bg-red-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
|
||||
@click="() => deleteGame(game.id)"
|
||||
>
|
||||
Delete
|
||||
|
||||
751
pages/admin/metadata/games/[id]/index.vue
Normal file
751
pages/admin/metadata/games/[id]/index.vue
Normal file
@ -0,0 +1,751 @@
|
||||
<!-- eslint-disable vue/no-v-html -->
|
||||
<template>
|
||||
<div>
|
||||
<div
|
||||
v-if="game && unimportedVersions !== undefined"
|
||||
class="grow flex flex-col gap-y-8"
|
||||
>
|
||||
<div class="grow w-full h-full lg:pr-[30vw] px-6 py-4 flex flex-col">
|
||||
<div
|
||||
class="flex flex-col lg:flex-row lg:justify-between items-start lg:items-center gap-2"
|
||||
>
|
||||
<div class="inline-flex items-center gap-4">
|
||||
<img :src="useObject(game.mIconObjectId)" class="size-20" />
|
||||
<div>
|
||||
<h1 class="text-5xl font-bold font-display text-zinc-100">
|
||||
{{ game.mName }}
|
||||
</h1>
|
||||
<p class="mt-1 text-lg text-zinc-400">
|
||||
{{ game.mShortDescription }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex gap-x-3 items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showEditCoreMetadata = true)"
|
||||
>
|
||||
Edit <PencilIcon class="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- image carousel pick -->
|
||||
<div class="border-b border-zinc-700">
|
||||
<div class="border-b border-zinc-700 py-4">
|
||||
<div
|
||||
class="-ml-4 -mt-4 flex flex-wrap items-center justify-between sm:flex-nowrap"
|
||||
>
|
||||
<div class="ml-4 mt-4">
|
||||
<h3 class="text-base font-semibold text-zinc-100">
|
||||
Image Carousel
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-zinc-400 max-w-lg">
|
||||
Customise what images and what order are shown on the store
|
||||
page.
|
||||
</p>
|
||||
</div>
|
||||
<div class="ml-4 mt-4 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showAddCarouselModal = true)"
|
||||
>
|
||||
Add from image library
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="game.mImageCarouselObjectIds.length == 0"
|
||||
class="text-zinc-400 text-center py-8"
|
||||
>
|
||||
No images added to the carousel yet.
|
||||
</div>
|
||||
|
||||
<draggable
|
||||
v-else
|
||||
:list="game.mImageCarouselObjectIds"
|
||||
class="w-full flex flex-row gap-x-4 overflow-x-auto my-2 py-4"
|
||||
@update="() => updateImageCarousel()"
|
||||
>
|
||||
<template #item="{ element }: { element: string }">
|
||||
<div class="relative group min-w-fit">
|
||||
<img :src="useObject(element)" class="h-48 w-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => removeImageFromCarousel(element)"
|
||||
>
|
||||
Remove image
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</draggable>
|
||||
</div>
|
||||
|
||||
<!-- description editor -->
|
||||
<div
|
||||
class="mt-4 grow flex flex-col w-full space-y-4 border border-zinc-800 rounded overflow-hidden p-2"
|
||||
>
|
||||
<!-- toolbar -->
|
||||
<div
|
||||
class="h-8 bg-zinc-800 rounded inline-flex gap-x-4 items-center justify-start p-2"
|
||||
>
|
||||
<div>
|
||||
<CheckIcon
|
||||
v-if="descriptionSaving == 0"
|
||||
class="size-5 text-zinc-100"
|
||||
/>
|
||||
<div v-else-if="descriptionSaving == 1">
|
||||
<PencilIcon class="animate-pulse size-5 text-zinc-100" />
|
||||
</div>
|
||||
<div v-else-if="descriptionSaving == 2" role="status">
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
class="w-5 h-5 text-transparent animate-spin fill-white"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button @click="() => (showAddImageDescriptionModal = true)">
|
||||
<PhotoIcon
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="block lg:hidden"
|
||||
@click="
|
||||
() => (mobileShowFinalDescription = !mobileShowFinalDescription)
|
||||
"
|
||||
>
|
||||
<DocumentIcon
|
||||
v-if="!mobileShowFinalDescription"
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
<PencilIcon
|
||||
v-else
|
||||
class="transition size-5 text-zinc-100 hover:text-zinc-300"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<!-- edit area -->
|
||||
<div class="grid lg:grid-cols-2 lg:gap-x-8 grow">
|
||||
<!-- editing box -->
|
||||
<div
|
||||
:class="[
|
||||
mobileShowFinalDescription ? 'hidden' : 'block',
|
||||
'lg:block',
|
||||
]"
|
||||
>
|
||||
<textarea
|
||||
ref="descriptionEditor"
|
||||
v-model="game.mDescription"
|
||||
class="grow h-full w-full bg-zinc-950/30 text-zinc-100 border-zinc-900 rounded"
|
||||
/>
|
||||
</div>
|
||||
<!-- result box -->
|
||||
<div
|
||||
:class="[
|
||||
mobileShowFinalDescription ? 'block' : 'hidden',
|
||||
'lg:block prose prose-invert prose-blue bg-zinc-950/30 rounded px-4 py-3',
|
||||
]"
|
||||
v-html="descriptionHTML"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="lg:overflow-y-auto lg:border-l lg:border-zinc-800 lg:fixed lg:inset-y-0 lg:z-50 lg:w-[30vw] flex flex-col lg:right-0 gap-y-8 px-6 py-4"
|
||||
>
|
||||
<!-- toolbar -->
|
||||
<div class="inline-flex justify-end items-stretch gap-x-4">
|
||||
<!-- open in library button -->
|
||||
<NuxtLink
|
||||
:href="`/admin/library/${game.id}`"
|
||||
type="button"
|
||||
class="inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open in Library →
|
||||
<ArrowTopRightOnSquareIcon
|
||||
class="-mr-0.5 h-7 w-7 p-1"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</NuxtLink>
|
||||
<!-- open in store button -->
|
||||
<NuxtLink
|
||||
:href="`/store/${game.id}`"
|
||||
type="button"
|
||||
class="inline-flex w-fit items-center gap-x-2 rounded-md bg-zinc-800 px-3 py-1 text-sm font-semibold font-display text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open in Store
|
||||
<ArrowTopRightOnSquareIcon
|
||||
class="-mr-0.5 h-7 w-7 p-1"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- image library -->
|
||||
<div>
|
||||
<div class="border-b border-zinc-800 pb-3">
|
||||
<div
|
||||
class="flex flex-wrap items-center justify-between sm:flex-nowrap gap-4"
|
||||
>
|
||||
<div>
|
||||
<h3
|
||||
class="text-base font-semibold font-display leading-6 text-zinc-100"
|
||||
>
|
||||
Image library
|
||||
</h3>
|
||||
<p class="mt-1 text-sm text-zinc-400 max-w-lg">
|
||||
Please note all images uploaded are accessible to all users
|
||||
through browser dev-tools.
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => (showUploadModal = true)"
|
||||
>
|
||||
Upload
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-2 grid-flow-dense gap-8">
|
||||
<div
|
||||
v-for="(image, imageIdx) in game.mImageLibraryObjectIds"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
v-if="image !== game.mBannerObjectId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => updateBannerImage(image)"
|
||||
>
|
||||
Set as banner
|
||||
</button>
|
||||
<button
|
||||
v-if="image !== game.mCoverObjectId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => updateCoverImage(image)"
|
||||
>
|
||||
Set as cover
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-red-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600"
|
||||
@click="() => deleteImage(image)"
|
||||
>
|
||||
Delete image
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="
|
||||
image === game.mBannerObjectId ||
|
||||
image === game.mCoverObjectId
|
||||
"
|
||||
class="absolute bottom-0 left-0 bg-zinc-950/75 text-zinc-100 text-sm font-semibold px-2 py-1 rounded-tr"
|
||||
>
|
||||
current
|
||||
{{
|
||||
[
|
||||
image === game.mBannerObjectId ? "banner" : undefined,
|
||||
image === game.mCoverObjectId ? "cover" : undefined,
|
||||
]
|
||||
.filter((e) => e)
|
||||
.join(" & ")
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<UploadFileDialog
|
||||
v-model="showUploadModal"
|
||||
:options="{ id: game.id }"
|
||||
accept="image/*"
|
||||
endpoint="/api/v1/admin/game/image"
|
||||
@upload="(result: Game) => uploadAfterImageUpload(result)"
|
||||
/>
|
||||
<ModalTemplate v-model="showAddCarouselModal">
|
||||
<template #default>
|
||||
<div class="grid grid-cols-2 grid-flow-dense gap-4">
|
||||
<div
|
||||
v-for="(image, imageIdx) in validAddCarouselImages"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => addImageToCarousel(image)"
|
||||
>
|
||||
Add
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="validAddCarouselImages.length == 0"
|
||||
class="text-zinc-400 col-span-2"
|
||||
>
|
||||
No images to add.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showAddCarouselModal = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
<ModalTemplate v-model="showAddImageDescriptionModal">
|
||||
<template #default>
|
||||
<div class="grid grid-cols-2 grid-flow-dense gap-4">
|
||||
<div
|
||||
v-for="(image, imageIdx) in game.mImageLibraryObjectIds"
|
||||
:key="imageIdx"
|
||||
class="group relative flex items-center bg-zinc-950/30"
|
||||
>
|
||||
<img :src="useObject(image)" class="w-full h-auto" />
|
||||
<div
|
||||
class="transition-all lg:opacity-0 lg:group-hover:opacity-100 absolute inset-0 flex flex-col items-center justify-center gap-y-2 bg-zinc-950/50"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-x-1.5 rounded-md bg-blue-600 px-1.5 py-0.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
@click="() => insertImageAtCursor(image)"
|
||||
>
|
||||
Insert
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="game.mImageLibraryObjectIds.length == 0"
|
||||
class="text-zinc-400 col-span-2"
|
||||
>
|
||||
No images to add.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showAddCarouselModal = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
<ModalTemplate v-model="showEditCoreMetadata">
|
||||
<template #default>
|
||||
<div class="flex flex-col lg:flex-row gap-6">
|
||||
<!-- icon upload div -->
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<img :src="coreMetadataIconUrl" class="size-24 aspect-square" />
|
||||
<label for="file-upload">
|
||||
<span
|
||||
type="button"
|
||||
class="cursor-pointer relative inline-flex items-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Upload
|
||||
</span>
|
||||
<input
|
||||
id="file-upload"
|
||||
accept="image/*"
|
||||
class="hidden"
|
||||
type="file"
|
||||
@change="(e) => coreMetadataUploadFiles(e as any)"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<!-- edit title -->
|
||||
<div class="flex flex-col gap-y-4 grow">
|
||||
<div>
|
||||
<label
|
||||
for="name"
|
||||
class="block text-sm/6 font-medium text-zinc-100"
|
||||
>Game Name</label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="name"
|
||||
v-model="coreMetadataName"
|
||||
type="text"
|
||||
name="name"
|
||||
class="block w-full rounded-md bg-zinc-800 px-3 py-1.5 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-zinc-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
for="description"
|
||||
class="block text-sm/6 font-medium text-zinc-100"
|
||||
>Game Description</label
|
||||
>
|
||||
<div class="mt-2">
|
||||
<input
|
||||
id="description"
|
||||
v-model="coreMetadataDescription"
|
||||
type="text"
|
||||
name="description"
|
||||
class="block w-full rounded-md bg-zinc-800 px-3 py-1.5 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-zinc-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:text-sm/6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #buttons>
|
||||
<LoadingButton
|
||||
type="button"
|
||||
:loading="coreMetadataLoading"
|
||||
:class="['inline-flex w-full shadow-sm sm:ml-3 sm:w-auto']"
|
||||
@click="() => coreMetadataUpdate_wrapper()"
|
||||
>
|
||||
Save
|
||||
</LoadingButton>
|
||||
<button
|
||||
ref="cancelButtonRef"
|
||||
type="button"
|
||||
class="mt-3 inline-flex w-full justify-center rounded-md bg-zinc-900 px-3 py-2 text-sm font-semibold text-zinc-100 shadow-sm ring-1 ring-inset ring-zinc-700 hover:bg-zinc-950 sm:mt-0 sm:w-auto"
|
||||
@click="showEditCoreMetadata = false"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</template>
|
||||
</ModalTemplate>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Game } from "~/prisma/client";
|
||||
import { micromark } from "micromark";
|
||||
import {
|
||||
ArrowTopRightOnSquareIcon,
|
||||
CheckIcon,
|
||||
DocumentIcon,
|
||||
PencilIcon,
|
||||
PhotoIcon,
|
||||
} from "@heroicons/vue/24/solid";
|
||||
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
const showUploadModal = ref(false);
|
||||
const showAddCarouselModal = ref(false);
|
||||
const showAddImageDescriptionModal = ref(false);
|
||||
const showEditCoreMetadata = ref(false);
|
||||
const mobileShowFinalDescription = ref(true);
|
||||
|
||||
const route = useRoute();
|
||||
const gameId = route.params.id.toString();
|
||||
const { game: rawGame, unimportedVersions } = await $dropFetch(
|
||||
`/api/v1/admin/game?id=${encodeURIComponent(gameId)}`,
|
||||
);
|
||||
const game = ref(rawGame);
|
||||
|
||||
const coreMetadataName = ref(game.value.mName);
|
||||
const coreMetadataDescription = ref(game.value.mShortDescription);
|
||||
const coreMetadataIconUrl = ref(useObject(game.value.mIconObjectId));
|
||||
const coreMetadataIconFileUpload = ref<FileList | undefined>();
|
||||
const coreMetadataLoading = ref(false);
|
||||
|
||||
function coreMetadataUploadFiles(e: InputEvent) {
|
||||
if (coreMetadataIconUrl.value.startsWith("blob")) {
|
||||
console.log("freed object URL");
|
||||
URL.revokeObjectURL(coreMetadataIconUrl.value);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
coreMetadataIconFileUpload.value = (e.target as any)?.files;
|
||||
const file = coreMetadataIconFileUpload.value?.item(0);
|
||||
if (!file) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to upload file",
|
||||
description: "Drop couldn't upload this file.",
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
coreMetadataIconUrl.value = objectUrl;
|
||||
}
|
||||
async function coreMetadataUpdate() {
|
||||
const formData = new FormData();
|
||||
|
||||
const newIcon = coreMetadataIconFileUpload.value?.item(0);
|
||||
if (newIcon) {
|
||||
formData.append("icon", newIcon);
|
||||
}
|
||||
|
||||
formData.append("id", game.value.id);
|
||||
formData.append("name", coreMetadataName.value);
|
||||
formData.append("description", coreMetadataDescription.value);
|
||||
|
||||
const result = await $dropFetch(`/api/v1/admin/game/metadata`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function coreMetadataUpdate_wrapper() {
|
||||
coreMetadataLoading.value = true;
|
||||
coreMetadataUpdate()
|
||||
.catch((e) => {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to update metadata",
|
||||
description: `Drop failed to update the game's metadata: ${
|
||||
e?.statusMessage || "An unknown error occurred. "
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
})
|
||||
.then((newGame) => {
|
||||
if (!newGame) return;
|
||||
Object.assign(game.value, newGame);
|
||||
})
|
||||
.finally(() => {
|
||||
coreMetadataLoading.value = false;
|
||||
showEditCoreMetadata.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
const descriptionHTML = computed(() =>
|
||||
micromark(game.value?.mDescription ?? ""),
|
||||
);
|
||||
const descriptionEditor = ref<HTMLTextAreaElement | undefined>();
|
||||
// 0 is not loading
|
||||
// 1 is waiting for stop
|
||||
// 2 is loading
|
||||
const descriptionSaving = ref<number>(0);
|
||||
|
||||
let savingTimeout: undefined | NodeJS.Timeout;
|
||||
|
||||
watch(descriptionHTML, (_v) => {
|
||||
console.log(game.value.mDescription);
|
||||
descriptionSaving.value = 1;
|
||||
if (savingTimeout) clearTimeout(savingTimeout);
|
||||
savingTimeout = setTimeout(async () => {
|
||||
try {
|
||||
descriptionSaving.value = 2;
|
||||
await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mDescription: game.value.mDescription,
|
||||
},
|
||||
});
|
||||
descriptionSaving.value = 0;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "Failed to update game description",
|
||||
description: `Drop failed to update the game description: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred."
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
const validAddCarouselImages = computed(() =>
|
||||
game.value.mImageLibraryObjectIds.filter(
|
||||
(e) => !game.value.mImageCarouselObjectIds.includes(e),
|
||||
),
|
||||
);
|
||||
|
||||
function insertImageAtCursor(id: string) {
|
||||
showAddImageDescriptionModal.value = false;
|
||||
if (!descriptionEditor.value || !game.value) return;
|
||||
const insertPosition = descriptionEditor.value.selectionStart;
|
||||
const text = ``;
|
||||
game.value.mDescription = `${game.value.mDescription.slice(
|
||||
0,
|
||||
insertPosition,
|
||||
)}${text}${game.value.mDescription.slice(insertPosition)}`;
|
||||
}
|
||||
|
||||
async function updateBannerImage(id: string) {
|
||||
try {
|
||||
if (game.value.mBannerObjectId == id) return;
|
||||
const { mBannerObjectId } = await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mBannerId: id,
|
||||
},
|
||||
});
|
||||
game.value.mBannerObjectId = mBannerObjectId;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the banner image",
|
||||
description: `Drop encountered an error while updating the banner image: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateCoverImage(id: string) {
|
||||
try {
|
||||
if (game.value.mCoverObjectId == id) return;
|
||||
const { mCoverObjectId } = await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mCoverId: id,
|
||||
},
|
||||
});
|
||||
game.value.mCoverObjectId = mCoverObjectId;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the cover image",
|
||||
description: `Drop encountered an error while updating the cover image: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteImage(id: string) {
|
||||
try {
|
||||
const { mBannerObjectId, mImageLibraryObjectIds } = await $dropFetch(
|
||||
"/api/v1/admin/game/image",
|
||||
{
|
||||
method: "DELETE",
|
||||
body: {
|
||||
gameId: game.value.id,
|
||||
imageId: id,
|
||||
},
|
||||
},
|
||||
);
|
||||
game.value.mImageLibraryObjectIds = mImageLibraryObjectIds;
|
||||
game.value.mBannerObjectId = mBannerObjectId;
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while deleting the image",
|
||||
description: `Drop encountered an error while deleting the image: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadAfterImageUpload(result: Game) {
|
||||
if (!game.value) return;
|
||||
game.value.mImageLibraryObjectIds = result.mImageLibraryObjectIds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function addImageToCarousel(id: string) {
|
||||
showAddCarouselModal.value = false;
|
||||
game.value.mImageCarouselObjectIds.push(id);
|
||||
updateImageCarousel();
|
||||
}
|
||||
|
||||
function removeImageFromCarousel(id: string) {
|
||||
const imageIndex = game.value.mImageCarouselObjectIds.findIndex(
|
||||
(e) => e == id,
|
||||
);
|
||||
game.value.mImageCarouselObjectIds.splice(imageIndex, 1);
|
||||
updateImageCarousel();
|
||||
}
|
||||
|
||||
async function updateImageCarousel() {
|
||||
try {
|
||||
await $dropFetch("/api/v1/admin/game", {
|
||||
method: "PATCH",
|
||||
body: {
|
||||
id: gameId,
|
||||
mImageCarousel: game.value.mImageCarouselObjectIds,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
createModal(
|
||||
ModalType.Notification,
|
||||
{
|
||||
title: "There an error while updating the image carousel",
|
||||
description: `Drop encountered an error while updating image carousel: ${
|
||||
// @ts-expect-error attempt to get statusMessage on error
|
||||
e?.statusMessage ?? "An unknown error occurred"
|
||||
}`,
|
||||
buttonText: "Close",
|
||||
},
|
||||
(e, c) => c(),
|
||||
);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
122
pages/admin/metadata/games/index.vue
Normal file
122
pages/admin/metadata/games/index.vue
Normal file
@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<div class="mx-auto max-w-2xl lg:mx-0">
|
||||
<h2
|
||||
class="mt-2 text-xl font-semibold tracking-tight text-zinc-100 sm:text-3xl"
|
||||
>
|
||||
Metadata Library
|
||||
</h2>
|
||||
<p
|
||||
class="mt-2 text-pretty text-sm font-medium text-gray-500 sm:text-md/8"
|
||||
>
|
||||
<span class="text-zinc-100 font-bold"
|
||||
>To import or delete games, visit the Library tab.</span
|
||||
>
|
||||
Here, you can edit and update your game's metadata.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-2 grid grid-cols-1">
|
||||
<input
|
||||
id="search"
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
name="search"
|
||||
class="col-start-1 row-start-1 block w-full rounded-md bg-zinc-900 py-1.5 pl-10 pr-3 text-base text-zinc-100 outline outline-1 -outline-offset-1 outline-zinc-700 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-blue-600 sm:pl-9 sm:text-sm/6"
|
||||
placeholder="Search library..."
|
||||
/>
|
||||
<MagnifyingGlassIcon
|
||||
class="pointer-events-none col-start-1 row-start-1 ml-3 size-5 self-center text-zinc-400 sm:size-4"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
<ul
|
||||
role="list"
|
||||
class="grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4"
|
||||
>
|
||||
<li
|
||||
v-for="game in filteredLibraryGames"
|
||||
:key="game.id"
|
||||
class="col-span-1 flex flex-col justify-center divide-y divide-zinc-700 rounded-lg bg-zinc-950/20 text-left shadow"
|
||||
>
|
||||
<div class="flex flex-1 flex-row p-4 gap-x-4">
|
||||
<img
|
||||
class="h-16 w-16 flex-shrink-0 rounded-md"
|
||||
:src="useObject(game.mIconObjectId)"
|
||||
alt=""
|
||||
/>
|
||||
<div class="flex flex-col">
|
||||
<h3 class="text-sm font-medium text-zinc-100 font-display">
|
||||
{{ game.mName }}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center rounded-full bg-blue-600/10 px-2 py-1 text-xs font-medium text-blue-600 ring-1 ring-inset ring-blue-600/20"
|
||||
>{{ game.metadataSource }}</span
|
||||
>
|
||||
</h3>
|
||||
<dl class="mt-1 flex flex-col justify-between">
|
||||
<dt class="sr-only">Short Description</dt>
|
||||
<dd class="text-sm text-zinc-400">
|
||||
{{ game.mShortDescription }}
|
||||
</dd>
|
||||
<dt class="sr-only">Metadata provider</dt>
|
||||
</dl>
|
||||
<div class="mt-4 flex flex-col gap-y-1">
|
||||
<NuxtLink
|
||||
:href="`/admin/metadata/games/${game.id}`"
|
||||
class="w-fit rounded-md bg-blue-600 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open with Metadata →
|
||||
</NuxtLink>
|
||||
<NuxtLink
|
||||
:href="`/admin/library/${game.id}`"
|
||||
class="w-fit rounded-md bg-zinc-800 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-zinc-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600"
|
||||
>
|
||||
Open with Library →
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<p
|
||||
v-if="filteredLibraryGames.length == 0 && libraryGames.length != 0"
|
||||
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
|
||||
>
|
||||
No results
|
||||
</p>
|
||||
<p
|
||||
v-if="filteredLibraryGames.length == 0 && libraryGames.length == 0"
|
||||
class="text-zinc-600 text-sm font-display font-bold uppercase text-center col-span-4"
|
||||
>
|
||||
No games imported
|
||||
</p>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { MagnifyingGlassIcon } from "@heroicons/vue/24/outline";
|
||||
definePageMeta({
|
||||
layout: "admin",
|
||||
});
|
||||
|
||||
useHead({
|
||||
title: "Game Library | Metadata",
|
||||
});
|
||||
|
||||
const searchQuery = ref("");
|
||||
|
||||
const libraryState = await $dropFetch("/api/v1/admin/library");
|
||||
const libraryGames = ref(libraryState.games.map((e) => e.game));
|
||||
|
||||
const filteredLibraryGames = computed(() =>
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore excessively deep ts
|
||||
libraryGames.value.filter((e) => {
|
||||
if (!searchQuery.value) return true;
|
||||
const searchQueryLower = searchQuery.value.toLowerCase();
|
||||
if (e.mName.toLowerCase().includes(searchQueryLower)) return true;
|
||||
if (e.mShortDescription.toLowerCase().includes(searchQueryLower))
|
||||
return true;
|
||||
return false;
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
@ -1,5 +1,39 @@
|
||||
<template>
|
||||
<div></div>
|
||||
<div class="space-y-4">
|
||||
<div class="mx-auto max-w-2xl lg:mx-0">
|
||||
<h2
|
||||
class="mt-2 text-xl font-semibold tracking-tight text-zinc-100 sm:text-3xl"
|
||||
>
|
||||
Metadata
|
||||
</h2>
|
||||
<p
|
||||
class="mt-2 text-pretty text-sm font-medium text-gray-500 sm:text-md/8"
|
||||
>
|
||||
Manage the metadata of your library, and update relationships between
|
||||
them. Users will be able to search through this metadata to find the
|
||||
games they want.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-5 gap-8">
|
||||
<NuxtLink
|
||||
to="/admin/metadata/games"
|
||||
class="transition group aspect-[3/2] flex flex-col justify-center items-center rounded-lg bg-zinc-950 hover:bg-zinc-950/50 shadow"
|
||||
>
|
||||
<span class="transition-all text-4xl font-bold text-zinc-300 group-hover:text-zinc-100 uppercase tracking-widest"
|
||||
>GAMES</span
|
||||
>
|
||||
</NuxtLink>
|
||||
<NuxtLink
|
||||
to="/admin/metadata/companies"
|
||||
class="transition group aspect-[3/2] flex flex-col justify-center items-center rounded-lg bg-zinc-950 hover:bg-zinc-950/50 shadow"
|
||||
>
|
||||
<span class="transition-all text-4xl font-bold text-zinc-300 group-hover:text-zinc-100 uppercase tracking-widest"
|
||||
>Companies</span
|
||||
>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
Reference in New Issue
Block a user