2024-07-15 09:36:07 -04:00
|
|
|
<script lang="ts">
|
2024-08-17 22:40:27 -04:00
|
|
|
import { enhance } from '$app/forms';
|
2024-08-07 13:01:12 -04:00
|
|
|
import { goto } from '$app/navigation';
|
2024-07-15 09:36:07 -04:00
|
|
|
import CollectionCard from '$lib/components/CollectionCard.svelte';
|
2024-12-26 21:56:14 -05:00
|
|
|
import CollectionLink from '$lib/components/CollectionLink.svelte';
|
2024-12-26 11:07:59 -05:00
|
|
|
import CollectionModal from '$lib/components/CollectionModal.svelte';
|
2024-07-15 09:36:07 -04:00
|
|
|
import NotFound from '$lib/components/NotFound.svelte';
|
2024-08-17 22:40:27 -04:00
|
|
|
import type { Collection } from '$lib/types';
|
2024-10-28 15:10:14 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-07-15 09:36:07 -04:00
|
|
|
|
|
|
|
import Plus from '~icons/mdi/plus';
|
|
|
|
|
|
|
|
export let data: any;
|
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
let collections: Collection[] = data.props.adventures || [];
|
|
|
|
|
|
|
|
let newType: string = '';
|
|
|
|
|
2024-08-04 22:19:09 -04:00
|
|
|
let resultsPerPage: number = 25;
|
2024-12-26 11:07:59 -05:00
|
|
|
let isShowingCollectionModal: boolean = false;
|
2024-07-15 09:36:07 -04:00
|
|
|
|
|
|
|
let next: string | null = data.props.next || null;
|
|
|
|
let previous: string | null = data.props.previous || null;
|
|
|
|
let count = data.props.count || 0;
|
|
|
|
let totalPages = Math.ceil(count / resultsPerPage);
|
|
|
|
let currentPage: number = 1;
|
|
|
|
|
2024-10-28 13:56:57 -04:00
|
|
|
$: {
|
|
|
|
if (count != collections.length) {
|
|
|
|
count = collections.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 09:36:07 -04:00
|
|
|
function handleChangePage() {
|
|
|
|
return async ({ result }: any) => {
|
|
|
|
if (result.type === 'success') {
|
|
|
|
console.log(result.data);
|
|
|
|
collections = result.data.body.adventures as Collection[];
|
|
|
|
next = result.data.body.next;
|
|
|
|
previous = result.data.body.previous;
|
|
|
|
count = result.data.body.count;
|
|
|
|
currentPage = result.data.body.page;
|
|
|
|
totalPages = Math.ceil(count / resultsPerPage);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSubmit() {
|
|
|
|
return async ({ result, update }: any) => {
|
|
|
|
// First, call the update function with reset: false
|
|
|
|
update({ reset: false });
|
|
|
|
|
|
|
|
// Then, handle the result
|
|
|
|
if (result.type === 'success') {
|
|
|
|
if (result.data) {
|
|
|
|
// console.log(result.data);
|
|
|
|
collections = result.data.adventures as Collection[];
|
|
|
|
next = result.data.next;
|
|
|
|
previous = result.data.previous;
|
|
|
|
count = result.data.count;
|
|
|
|
totalPages = Math.ceil(count / resultsPerPage);
|
|
|
|
currentPage = 1;
|
|
|
|
|
|
|
|
console.log(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-08-13 12:03:18 -04:00
|
|
|
function deleteCollection(event: CustomEvent<string>) {
|
2024-07-15 12:09:20 -04:00
|
|
|
collections = collections.filter((collection) => collection.id !== event.detail);
|
|
|
|
}
|
|
|
|
|
2024-12-26 21:56:14 -05:00
|
|
|
// function sort({ attribute, order }: { attribute: string; order: string }) {
|
|
|
|
// currentSort.attribute = attribute;
|
|
|
|
// currentSort.order = order;
|
|
|
|
// if (attribute === 'name') {
|
|
|
|
// if (order === 'asc') {
|
|
|
|
// collections = collections.sort((a, b) => b.name.localeCompare(a.name));
|
|
|
|
// } else {
|
|
|
|
// collections = collections.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2024-07-15 09:36:07 -04:00
|
|
|
|
2024-12-26 11:07:59 -05:00
|
|
|
let collectionToEdit: Collection | null = null;
|
2024-07-15 09:36:07 -04:00
|
|
|
|
2024-12-26 21:56:14 -05:00
|
|
|
function saveOrCreate(event: CustomEvent<Collection>) {
|
|
|
|
if (collections.find((collection) => collection.id === event.detail.id)) {
|
|
|
|
collections = collections.map((collection) => {
|
|
|
|
if (collection.id === event.detail.id) {
|
|
|
|
return event.detail;
|
|
|
|
}
|
|
|
|
return collection;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
collections = [event.detail, ...collections];
|
|
|
|
}
|
2024-12-26 11:07:59 -05:00
|
|
|
isShowingCollectionModal = false;
|
2024-07-15 09:36:07 -04:00
|
|
|
}
|
|
|
|
|
2024-07-15 18:01:49 -04:00
|
|
|
function editCollection(event: CustomEvent<Collection>) {
|
2024-07-15 09:36:07 -04:00
|
|
|
collectionToEdit = event.detail;
|
2024-12-26 11:07:59 -05:00
|
|
|
isShowingCollectionModal = true;
|
2024-07-15 09:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveEdit(event: CustomEvent<Collection>) {
|
|
|
|
collections = collections.map((adventure) => {
|
|
|
|
if (adventure.id === event.detail.id) {
|
|
|
|
return event.detail;
|
|
|
|
}
|
|
|
|
return adventure;
|
|
|
|
});
|
2024-12-26 11:07:59 -05:00
|
|
|
isShowingCollectionModal = false;
|
2024-07-15 09:36:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let sidebarOpen = false;
|
|
|
|
|
|
|
|
function toggleSidebar() {
|
|
|
|
sidebarOpen = !sidebarOpen;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2024-12-26 11:07:59 -05:00
|
|
|
{#if isShowingCollectionModal}
|
|
|
|
<CollectionModal
|
2024-07-15 18:01:49 -04:00
|
|
|
{collectionToEdit}
|
2024-12-26 11:07:59 -05:00
|
|
|
on:close={() => (isShowingCollectionModal = false)}
|
2024-07-15 09:36:07 -04:00
|
|
|
on:saveEdit={saveEdit}
|
2024-12-26 21:56:14 -05:00
|
|
|
on:save={saveOrCreate}
|
2024-07-15 09:36:07 -04:00
|
|
|
/>
|
2024-07-15 18:01:49 -04:00
|
|
|
{/if}
|
2024-07-15 09:36:07 -04:00
|
|
|
<div class="fixed bottom-4 right-4 z-[999]">
|
|
|
|
<div class="flex flex-row items-center justify-center gap-4">
|
|
|
|
<div class="dropdown dropdown-top dropdown-end">
|
|
|
|
<div tabindex="0" role="button" class="btn m-1 size-16 btn-primary">
|
|
|
|
<Plus class="w-8 h-8" />
|
|
|
|
</div>
|
|
|
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
|
|
<ul
|
|
|
|
tabindex="0"
|
|
|
|
class="dropdown-content z-[1] menu p-4 shadow bg-base-300 text-base-content rounded-box w-52 gap-4"
|
|
|
|
>
|
2024-10-28 15:10:14 -04:00
|
|
|
<p class="text-center font-bold text-lg">{$t(`adventures.create_new`)}</p>
|
2024-07-15 09:36:07 -04:00
|
|
|
<button
|
|
|
|
class="btn btn-primary"
|
|
|
|
on:click={() => {
|
2024-12-26 11:07:59 -05:00
|
|
|
collectionToEdit = null;
|
|
|
|
isShowingCollectionModal = true;
|
2024-07-15 09:36:07 -04:00
|
|
|
newType = 'visited';
|
|
|
|
}}
|
|
|
|
>
|
2024-10-28 15:10:14 -04:00
|
|
|
{$t(`adventures.collection`)}</button
|
2024-07-15 09:36:07 -04:00
|
|
|
>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="drawer lg:drawer-open">
|
|
|
|
<input id="my-drawer" type="checkbox" class="drawer-toggle" bind:checked={sidebarOpen} />
|
|
|
|
<div class="drawer-content">
|
|
|
|
<!-- Page content -->
|
2024-10-28 15:10:14 -04:00
|
|
|
<h1 class="text-center font-bold text-4xl mb-6">{$t(`adventures.my_collections`)}</h1>
|
|
|
|
<p class="text-center">{count} {$t(`adventures.count_txt`)}</p>
|
2024-07-15 09:36:07 -04:00
|
|
|
{#if collections.length === 0}
|
2024-07-18 18:37:46 -04:00
|
|
|
<NotFound error={undefined} />
|
2024-07-15 09:36:07 -04:00
|
|
|
{/if}
|
|
|
|
<div class="p-4">
|
|
|
|
<button
|
|
|
|
class="btn btn-primary drawer-button lg:hidden mb-4 fixed bottom-0 left-0 ml-2 z-[999]"
|
|
|
|
on:click={toggleSidebar}
|
|
|
|
>
|
2024-10-28 15:10:14 -04:00
|
|
|
{sidebarOpen ? $t(`adventures.close_filters`) : $t(`adventures.open_filters`)}
|
2024-07-15 09:36:07 -04:00
|
|
|
</button>
|
2024-08-05 14:17:41 -04:00
|
|
|
|
|
|
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
|
|
|
{#each collections as collection}
|
|
|
|
<CollectionCard
|
|
|
|
type=""
|
|
|
|
{collection}
|
|
|
|
on:delete={deleteCollection}
|
|
|
|
on:edit={editCollection}
|
2024-10-13 23:23:32 -04:00
|
|
|
adventures={collection.adventures}
|
2024-08-05 14:17:41 -04:00
|
|
|
/>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
2024-07-15 09:36:07 -04:00
|
|
|
<div class="join flex items-center justify-center mt-4">
|
|
|
|
{#if next || previous}
|
|
|
|
<div class="join">
|
|
|
|
{#each Array.from({ length: totalPages }, (_, i) => i + 1) as page}
|
|
|
|
<form action="?/changePage" method="POST" use:enhance={handleChangePage}>
|
|
|
|
<input type="hidden" name="page" value={page} />
|
|
|
|
<input type="hidden" name="next" value={next} />
|
|
|
|
<input type="hidden" name="previous" value={previous} />
|
|
|
|
{#if currentPage != page}
|
|
|
|
<button class="join-item btn btn-lg">{page}</button>
|
|
|
|
{:else}
|
|
|
|
<button class="join-item btn btn-lg btn-active">{page}</button>
|
|
|
|
{/if}
|
|
|
|
</form>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="drawer-side">
|
|
|
|
<label for="my-drawer" class="drawer-overlay"></label>
|
|
|
|
<ul class="menu p-4 w-80 h-full bg-base-200 text-base-content rounded-lg">
|
|
|
|
<!-- Sidebar content here -->
|
|
|
|
<div class="form-control">
|
|
|
|
<form action="?/get" method="post" use:enhance={handleSubmit}>
|
2024-10-28 15:10:14 -04:00
|
|
|
<h3 class="text-center font-semibold text-lg mb-4">{$t(`adventures.sort`)}</h3>
|
|
|
|
<p class="text-lg font-semibold mb-2">{$t(`adventures.order_direction`)}</p>
|
2024-07-19 09:05:47 -04:00
|
|
|
<div class="join">
|
|
|
|
<input
|
|
|
|
class="join-item btn btn-neutral"
|
|
|
|
type="radio"
|
|
|
|
name="order_direction"
|
|
|
|
id="asc"
|
|
|
|
value="asc"
|
2024-10-28 15:10:14 -04:00
|
|
|
aria-label={$t(`adventures.ascending`)}
|
2024-07-19 09:05:47 -04:00
|
|
|
checked
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn btn-neutral"
|
|
|
|
type="radio"
|
|
|
|
name="order_direction"
|
|
|
|
id="desc"
|
|
|
|
value="desc"
|
2024-10-28 15:10:14 -04:00
|
|
|
aria-label={$t(`adventures.descending`)}
|
2024-07-19 09:05:47 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2025-03-21 17:31:33 -04:00
|
|
|
<p class="text-lg font-semibold mt-2 mb-2">{$t('adventures.order_by')}</p>
|
|
|
|
<div class="join">
|
|
|
|
<input
|
|
|
|
class="join-item btn btn-neutral"
|
|
|
|
type="radio"
|
|
|
|
name="order_by"
|
|
|
|
id="upated_at"
|
|
|
|
value="upated_at"
|
|
|
|
aria-label={$t('adventures.updated')}
|
|
|
|
checked
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn btn-neutral"
|
|
|
|
type="radio"
|
|
|
|
name="order_by"
|
|
|
|
id="start_date"
|
|
|
|
value="start_date"
|
|
|
|
aria-label={$t('adventures.start_date')}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
class="join-item btn btn-neutral"
|
|
|
|
type="radio"
|
|
|
|
name="order_by"
|
|
|
|
id="name"
|
|
|
|
value="name"
|
|
|
|
aria-label={$t('adventures.name')}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-07-15 09:36:07 -04:00
|
|
|
<br />
|
2024-07-16 09:26:45 -04:00
|
|
|
|
2024-10-28 15:10:14 -04:00
|
|
|
<button type="submit" class="btn btn-success btn-primary mt-4"
|
|
|
|
>{$t(`adventures.sort`)}</button
|
|
|
|
>
|
2024-07-15 09:36:07 -04:00
|
|
|
</form>
|
|
|
|
<div class="divider"></div>
|
2024-08-07 13:01:12 -04:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-neutral btn-primary mt-4"
|
2024-10-28 15:10:14 -04:00
|
|
|
on:click={() => goto('/collections/archived')}
|
|
|
|
>{$t(`adventures.archived_collections`)}</button
|
2024-08-07 13:01:12 -04:00
|
|
|
>
|
2024-07-15 09:36:07 -04:00
|
|
|
</div>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-06 08:50:15 -04:00
|
|
|
|
|
|
|
<svelte:head>
|
2024-12-26 21:56:14 -05:00
|
|
|
<title>Collections</title>
|
2024-08-06 08:50:15 -04:00
|
|
|
<meta name="description" content="View your adventure collections." />
|
|
|
|
</svelte:head>
|