1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 14:59:36 +02:00
This commit is contained in:
Sean Morley 2024-07-18 14:55:23 -04:00
parent 5e70130000
commit e650a81109
6 changed files with 61 additions and 49 deletions

View file

@ -143,6 +143,8 @@ class AdventureViewSet(viewsets.ModelViewSet):
@action(detail=False, methods=['get']) @action(detail=False, methods=['get'])
def search(self, request): def search(self, request):
query = self.request.query_params.get('query', '') query = self.request.query_params.get('query', '')
if len(query) < 2:
return Response({"error": "Query must be at least 2 characters long"}, status=400)
queryset = Adventure.objects.filter( queryset = Adventure.objects.filter(
(Q(name__icontains=query) | Q(description__icontains=query) | Q(location__icontains=query) | Q(activity_types__icontains=query)) & (Q(name__icontains=query) | Q(description__icontains=query) | Q(location__icontains=query) | Q(activity_types__icontains=query)) &
(Q(user_id=request.user.id) | Q(is_public=True)) (Q(user_id=request.user.id) | Q(is_public=True))

View file

@ -161,6 +161,7 @@
{/if} {/if}
<div class="card-actions justify-end mt-2"> <div class="card-actions justify-end mt-2">
<!-- action options dropdown --> <!-- action options dropdown -->
{#if type != 'link'}
<div class="dropdown dropdown-end"> <div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-neutral"> <div tabindex="0" role="button" class="btn btn-neutral">
<DotsHorizontal class="w-6 h-6" /> <DotsHorizontal class="w-6 h-6" />
@ -170,7 +171,9 @@
tabindex="0" tabindex="0"
class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow" class="dropdown-content menu bg-base-100 rounded-box z-[1] w-52 p-2 shadow"
> >
<button class="btn btn-neutral mb-2" on:click={() => goto(`/adventures/${adventure.id}`)} <button
class="btn btn-neutral mb-2"
on:click={() => goto(`/adventures/${adventure.id}`)}
><Launch class="w-6 h-6" />Open Details</button ><Launch class="w-6 h-6" />Open Details</button
> >
<button class="btn btn-neutral mb-2" on:click={editAdventure}> <button class="btn btn-neutral mb-2" on:click={editAdventure}>
@ -196,14 +199,15 @@
><Plus class="w-6 h-6" />Add to Collection</button ><Plus class="w-6 h-6" />Add to Collection</button
> >
{/if} {/if}
{#if type == 'link'}
<button class="btn btn-primary" on:click={link}><Link class="w-6 h-6" /></button>
{/if}
<button class="btn btn-warning" on:click={deleteAdventure} <button class="btn btn-warning" on:click={deleteAdventure}
><TrashCan class="w-6 h-6" />Delete</button ><TrashCan class="w-6 h-6" />Delete</button
> >
</ul> </ul>
</div> </div>
{/if}
{#if type == 'link'}
<button class="btn btn-primary" on:click={link}><Link class="w-6 h-6" /></button>
{/if}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import Lost from '$lib/assets/undraw_lost.svg'; import Lost from '$lib/assets/undraw_lost.svg';
export let error: string | undefined;
</script> </script>
<div <div
@ -12,9 +13,13 @@
<h1 class="mt-4 text-3xl font-bold tracking-tight text-foreground sm:text-4xl"> <h1 class="mt-4 text-3xl font-bold tracking-tight text-foreground sm:text-4xl">
No adventures found No adventures found
</h1> </h1>
{#if !error}
<p class="mt-4 text-muted-foreground"> <p class="mt-4 text-muted-foreground">
There are no adventures to display. Add some using the plus button at the bottom right or try There are no adventures to display. Add some using the plus button at the bottom right or
changing filters! try changing filters!
</p> </p>
{:else}
<p class="text-error mt-2">{error}</p>
{/if}
</div> </div>
</div> </div>

View file

@ -172,7 +172,7 @@
<h1 class="text-center font-bold text-4xl mb-6">My Adventures</h1> <h1 class="text-center font-bold text-4xl mb-6">My Adventures</h1>
<p class="text-center">This search returned {count} results.</p> <p class="text-center">This search returned {count} results.</p>
{#if adventures.length === 0} {#if adventures.length === 0}
<NotFound /> <NotFound error={undefined} />
{/if} {/if}
<div class="p-4"> <div class="p-4">
<button <button

View file

@ -34,6 +34,7 @@ export const load = (async (event) => {
}; };
} else { } else {
console.error('Failed to fetch search data'); console.error('Failed to fetch search data');
return { data: [] }; let error = await res.json();
return { error: error.error };
} }
}) satisfies PageServerLoad; }) satisfies PageServerLoad;

View file

@ -18,7 +18,7 @@
</script> </script>
{#if adventures.length === 0} {#if adventures.length === 0}
<NotFound /> <NotFound error={data.error} />
{:else} {:else}
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center"> <div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure} {#each adventures as adventure}