refactor: remove archived collections page and related components; enhance world travel pages with improved UI and filtering options

This commit is contained in:
Sean Morley
2025-06-13 21:41:10 -04:00
parent 14eb4ca802
commit a99553ba0d
9 changed files with 797 additions and 361 deletions

View File

@@ -63,28 +63,32 @@
}
}
// Reactive statements to update collections based on props
$: {
async function goToPage(pageNum: number) {
const url = new URL($page.url);
url.searchParams.set('page', pageNum.toString());
await goto(url.toString(), { invalidateAll: true, replaceState: true });
if (data.props.adventures) {
collections = data.props.adventures;
}
if (data.props.archivedCollections) {
archivedCollections = data.props.archivedCollections;
}
currentPage = pageNum;
}
function goToPage(pageNum: number) {
const url = new URL($page.url);
url.searchParams.set('page', pageNum.toString());
goto(url.toString(), { invalidateAll: true, replaceState: true });
}
function updateSort(by: string, direction: string) {
async function updateSort(by: string, direction: string) {
const url = new URL($page.url);
url.searchParams.set('order_by', by);
url.searchParams.set('order_direction', direction);
url.searchParams.set('page', '1'); // Reset to first page when sorting changes
goto(url.toString(), { invalidateAll: true, replaceState: true });
currentPage = 1;
await goto(url.toString(), { invalidateAll: true, replaceState: true });
if (data.props.adventures) {
collections = data.props.adventures;
}
if (data.props.archivedCollections) {
archivedCollections = data.props.archivedCollections;
}
}
function deleteCollection(event: CustomEvent<string>) {
@@ -98,6 +102,7 @@
function archiveCollection(event: CustomEvent<string>) {
const collectionId = event.detail;
console.log('Archiving collection with ID:', collectionId);
// Find the collection in owned collections
const collectionToArchive = collections.find((collection) => collection.id === collectionId);
@@ -106,9 +111,6 @@
collections = collections.filter((collection) => collection.id !== collectionId);
// Add to archived collections
archivedCollections = [...archivedCollections, { ...collectionToArchive, is_archived: true }];
// Automatically switch to archived tab to show the archived item
activeView = 'archived';
}
}
@@ -126,9 +128,6 @@
);
// Add to owned collections
collections = [...collections, { ...collectionToUnarchive, is_archived: false }];
// Automatically switch to owned tab to show the unarchived item
activeView = 'owned';
}
}

View File

@@ -1,33 +0,0 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
import type { Adventure } from '$lib/types';
const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const load = (async (event) => {
if (!event.locals.user) {
return redirect(302, '/login');
} else {
let sessionId = event.cookies.get('sessionid');
let adventures: Adventure[] = [];
let initialFetch = await fetch(`${serverEndpoint}/api/collections/archived/`, {
headers: {
Cookie: `sessionid=${sessionId}`
}
});
if (!initialFetch.ok) {
console.error('Failed to fetch visited adventures');
return redirect(302, '/login');
} else {
let res = await initialFetch.json();
let visited = res as Adventure[];
adventures = [...adventures, ...visited];
}
return {
props: {
adventures
}
};
}
}) satisfies PageServerLoad;

View File

@@ -1,37 +0,0 @@
<script lang="ts">
import CollectionCard from '$lib/components/CollectionCard.svelte';
import NotFound from '$lib/components/NotFound.svelte';
import type { Collection } from '$lib/types';
import { t } from 'svelte-i18n';
export let data: any;
console.log(data);
let collections: Collection[] = data.props.adventures || [];
function deleteCollection(event: CustomEvent<string>) {
collections = collections.filter((collection) => collection.id !== event.detail);
}
</script>
<div class="drawer lg:drawer-open">
<div class="drawer-content">
<!-- Page content -->
<h1 class="text-center font-bold text-4xl mb-6">{$t('adventures.archived_collections')}</h1>
{#if collections.length === 0}
<NotFound error={undefined} />
{/if}
<div class="p-4">
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each collections as collection}
<CollectionCard type="" {collection} on:delete={deleteCollection} />
{/each}
</div>
</div>
</div>
</div>
<svelte:head>
<title>Collections</title>
<meta name="description" content="View your adventure collections." />
</svelte:head>