2024-07-16 09:12:53 -04:00
|
|
|
<script lang="ts">
|
|
|
|
import type { Adventure, Collection } from '$lib/types';
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
import CollectionCard from './CollectionCard.svelte';
|
|
|
|
let modal: HTMLDialogElement;
|
2024-10-30 15:11:00 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-07-16 09:12:53 -04:00
|
|
|
|
|
|
|
let collections: Collection[] = [];
|
|
|
|
|
2025-06-12 15:54:01 -04:00
|
|
|
export let linkedCollectionList: string[] | null = null;
|
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
onMount(async () => {
|
|
|
|
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
|
|
|
|
if (modal) {
|
|
|
|
modal.showModal();
|
|
|
|
}
|
2025-06-14 22:16:39 -04:00
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
let res = await fetch(`/api/collections/all/`, {
|
|
|
|
method: 'GET'
|
|
|
|
});
|
|
|
|
|
|
|
|
let result = await res.json();
|
|
|
|
|
|
|
|
if (result.type === 'success' && result.data) {
|
|
|
|
collections = result.data.adventures as Collection[];
|
2025-06-14 22:16:39 -04:00
|
|
|
} else {
|
|
|
|
collections = result as Collection[];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move linked collections to the front
|
|
|
|
if (linkedCollectionList) {
|
|
|
|
collections.sort((a, b) => {
|
|
|
|
const aLinked = linkedCollectionList?.includes(a.id);
|
|
|
|
const bLinked = linkedCollectionList?.includes(b.id);
|
|
|
|
return aLinked === bLinked ? 0 : aLinked ? -1 : 1;
|
|
|
|
});
|
2024-07-16 09:12:53 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
dispatch('close');
|
|
|
|
}
|
|
|
|
|
2025-06-12 15:54:01 -04:00
|
|
|
function link(event: CustomEvent<string>) {
|
2024-07-16 09:12:53 -04:00
|
|
|
dispatch('link', event.detail);
|
|
|
|
}
|
|
|
|
|
2025-06-12 15:54:01 -04:00
|
|
|
function unlink(event: CustomEvent<string>) {
|
|
|
|
dispatch('unlink', event.detail);
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:12:53 -04:00
|
|
|
function handleKeydown(event: KeyboardEvent) {
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
dispatch('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<dialog id="my_modal_1" class="modal">
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
|
|
<div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0">
|
2024-10-30 15:11:00 -04:00
|
|
|
<h1 class="text-center font-bold text-4xl mb-6">{$t('adventures.my_collections')}</h1>
|
2025-06-12 15:54:01 -04:00
|
|
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center mb-4">
|
2024-07-16 09:12:53 -04:00
|
|
|
{#each collections as collection}
|
2025-06-12 15:54:01 -04:00
|
|
|
<CollectionCard
|
|
|
|
{collection}
|
|
|
|
type="link"
|
|
|
|
on:link={link}
|
|
|
|
bind:linkedCollectionList
|
|
|
|
on:unlink={unlink}
|
2025-06-13 21:41:10 -04:00
|
|
|
user={null}
|
2025-06-12 15:54:01 -04:00
|
|
|
/>
|
2024-07-16 09:12:53 -04:00
|
|
|
{/each}
|
|
|
|
{#if collections.length === 0}
|
2024-10-30 15:11:00 -04:00
|
|
|
<p class="text-center text-lg">{$t('adventures.no_collections_found')}</p>
|
2024-07-16 09:12:53 -04:00
|
|
|
{/if}
|
|
|
|
</div>
|
2024-10-30 15:11:00 -04:00
|
|
|
<button class="btn btn-primary" on:click={close}>{$t('about.close')}</button>
|
2024-07-16 09:12:53 -04:00
|
|
|
</div>
|
|
|
|
</dialog>
|