diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index 31c2d8e..2018e99 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -402,6 +402,18 @@ class CollectionViewSet(viewsets.ModelViewSet): return Response(serializer.data) + # make an action to retreive all adventures that are shared with the user + @action(detail=False, methods=['get']) + def shared(self, request): + if not request.user.is_authenticated: + return Response({"error": "User is not authenticated"}, status=400) + queryset = Collection.objects.filter( + shared_with=request.user + ) + queryset = self.apply_sorting(queryset) + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data) + # Adds a new user to the shared_with field of an adventure @action(detail=True, methods=['post'], url_path='share/(?P[^/.]+)') def share(self, request, pk=None, uuid=None): diff --git a/frontend/src/lib/components/Avatar.svelte b/frontend/src/lib/components/Avatar.svelte index 734aee8..c074250 100644 --- a/frontend/src/lib/components/Avatar.svelte +++ b/frontend/src/lib/components/Avatar.svelte @@ -32,6 +32,7 @@
  • +
  • diff --git a/frontend/src/lib/components/CollectionCard.svelte b/frontend/src/lib/components/CollectionCard.svelte index 882e8e4..519ddfd 100644 --- a/frontend/src/lib/components/CollectionCard.svelte +++ b/frontend/src/lib/components/CollectionCard.svelte @@ -131,7 +131,7 @@ tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow" > - {#if type != 'link'} + {#if type != 'link' && type != 'viewonly'} {/if} + {#if type == 'viewonly'} + + {/if} {/if} diff --git a/frontend/src/routes/shared/+page.server.ts b/frontend/src/routes/shared/+page.server.ts new file mode 100644 index 0000000..b40dbac --- /dev/null +++ b/frontend/src/routes/shared/+page.server.ts @@ -0,0 +1,26 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; + +const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL']; +const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + +export const load = (async (event) => { + if (!event.locals.user) { + return redirect(302, '/login'); + } else { + let res = await fetch(`${serverEndpoint}/api/collections/shared/`, { + headers: { + Cookie: `${event.cookies.get('auth')}` + } + }); + if (!res.ok) { + return redirect(302, '/login'); + } else { + return { + props: { + collections: await res.json() + } + }; + } + } +}) satisfies PageServerLoad; diff --git a/frontend/src/routes/shared/+page.svelte b/frontend/src/routes/shared/+page.svelte new file mode 100644 index 0000000..7aa0e6c --- /dev/null +++ b/frontend/src/routes/shared/+page.svelte @@ -0,0 +1,27 @@ + + +{#if collections.length > 0} +
    + {#each collections as collection} + + {/each} +
    +{:else} +

    + No collections found that are shared with you. + {#if data.user && !data.user?.public_profile} +

    In order to allow users to share with you, you need your profile set to public.

    + + {/if} +

    +{/if}