From 14eb4ca8029808d4b405c03f71f9648b003c6811 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Fri, 13 Jun 2025 12:11:42 -0400 Subject: [PATCH] feat(collections): enhance collections page with sorting, filtering, and pagination features - Updated the collections loading logic to include sorting and pagination parameters from the URL. - Refactored the collections page to manage owned, shared, and archived collections with a tabbed interface. - Added sorting functionality to allow users to sort collections by different attributes. - Implemented a sidebar for filtering and sorting options. - Improved the UI for better user experience, including a floating action button for creating new collections. - Added a not found page for collections that do not exist, enhancing error handling. --- backend/server/adventures/serializers.py | 2 - .../adventures/views/collection_view.py | 3 +- .../src/lib/components/AdventureModal.svelte | 4 +- frontend/src/lib/components/Avatar.svelte | 2 +- .../src/lib/components/CollectionCard.svelte | 125 +- .../src/lib/components/CollectionModal.svelte | 22 + frontend/src/lib/components/Navbar.svelte | 2 +- frontend/src/locales/de.json | 9 +- frontend/src/locales/en.json | 2 + frontend/src/locales/es.json | 13 +- frontend/src/locales/fr.json | 9 +- frontend/src/locales/it.json | 9 +- frontend/src/locales/ko.json | 9 +- frontend/src/locales/nl.json | 9 +- frontend/src/locales/no.json | 9 +- frontend/src/locales/pl.json | 9 +- frontend/src/locales/ru.json | 1457 +++++++++-------- frontend/src/locales/sv.json | 9 +- frontend/src/locales/zh.json | 9 +- frontend/src/routes/adventures/+page.svelte | 573 ++++--- .../src/routes/collections/+page.server.ts | 55 +- frontend/src/routes/collections/+page.svelte | 579 ++++--- .../src/routes/collections/[id]/+page.svelte | 22 +- 23 files changed, 1691 insertions(+), 1251 deletions(-) diff --git a/backend/server/adventures/serializers.py b/backend/server/adventures/serializers.py index 4985d2d..3023e04 100644 --- a/backend/server/adventures/serializers.py +++ b/backend/server/adventures/serializers.py @@ -209,8 +209,6 @@ class AdventureSerializer(CustomModelSerializer): category_data = validated_data.pop('category', None) collections_data = validated_data.pop('collections', None) - collections_add = validated_data.pop('collections_add', []) - collections_remove = validated_data.pop('collections_remove', []) # Update regular fields for attr, value in validated_data.items(): diff --git a/backend/server/adventures/views/collection_view.py b/backend/server/adventures/views/collection_view.py index fca9986..40ebbd6 100644 --- a/backend/server/adventures/views/collection_view.py +++ b/backend/server/adventures/views/collection_view.py @@ -55,7 +55,7 @@ class CollectionViewSet(viewsets.ModelViewSet): # make sure the user is authenticated if not request.user.is_authenticated: return Response({"error": "User is not authenticated"}, status=400) - queryset = Collection.objects.filter(user_id=request.user.id) + queryset = Collection.objects.filter(user_id=request.user.id, is_archived=False) queryset = self.apply_sorting(queryset) collections = self.paginate_and_respond(queryset, request) return collections @@ -226,7 +226,6 @@ class CollectionViewSet(viewsets.ModelViewSet): (Q(user_id=self.request.user.id) | Q(shared_with=self.request.user)) & Q(is_archived=False) ).distinct() - def perform_create(self, serializer): # This is ok because you cannot share a collection when creating it serializer.save(user_id=self.request.user) diff --git a/frontend/src/lib/components/AdventureModal.svelte b/frontend/src/lib/components/AdventureModal.svelte index e8b7d6e..4c2e07a 100644 --- a/frontend/src/lib/components/AdventureModal.svelte +++ b/frontend/src/lib/components/AdventureModal.svelte @@ -112,7 +112,6 @@ location: null, images: [], user_id: null, - collection: collection?.id || null, category: { id: '', name: '', @@ -138,7 +137,6 @@ location: adventureToEdit?.location || null, images: adventureToEdit?.images || [], user_id: adventureToEdit?.user_id || null, - collection: adventureToEdit?.collection || collection?.id || null, visits: adventureToEdit?.visits || [], is_visited: adventureToEdit?.is_visited || false, category: adventureToEdit?.category || { @@ -628,7 +626,7 @@

{wikiError}

- {#if !adventure?.collection} + {#if adventure.collections && adventure.collections.length == 0}
{/if}
diff --git a/frontend/src/lib/components/CollectionModal.svelte b/frontend/src/lib/components/CollectionModal.svelte index 93ec776..dfcc88d 100644 --- a/frontend/src/lib/components/CollectionModal.svelte +++ b/frontend/src/lib/components/CollectionModal.svelte @@ -219,6 +219,28 @@ {$t('about.close')} + + {#if collection.is_public && collection.id} +
+

{$t('adventures.share_collection')}

+
+

+ {window.location.origin}/collections/{collection.id} +

+ +
+
+ {/if} diff --git a/frontend/src/lib/components/Navbar.svelte b/frontend/src/lib/components/Navbar.svelte index f655454..4f3ad9a 100644 --- a/frontend/src/lib/components/Navbar.svelte +++ b/frontend/src/lib/components/Navbar.svelte @@ -277,7 +277,7 @@ {#if data.user} {/if} -