1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 06:49:37 +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'])
def search(self, request):
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(
(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))

View file

@ -161,6 +161,7 @@
{/if}
<div class="card-actions justify-end mt-2">
<!-- action options dropdown -->
{#if type != 'link'}
<div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-neutral">
<DotsHorizontal class="w-6 h-6" />
@ -170,7 +171,9 @@
tabindex="0"
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
>
<button class="btn btn-neutral mb-2" on:click={editAdventure}>
@ -196,14 +199,15 @@
><Plus class="w-6 h-6" />Add to Collection</button
>
{/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}
><TrashCan class="w-6 h-6" />Delete</button
>
</ul>
</div>
{/if}
{#if type == 'link'}
<button class="btn btn-primary" on:click={link}><Link class="w-6 h-6" /></button>
{/if}
</div>
</div>
</div>

View file

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

View file

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

View file

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

View file

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