feat: enhance user feedback with toast notifications for various actions and errors

This commit is contained in:
maxDorninger
2025-05-24 20:58:54 +02:00
parent 6513065ba8
commit 0ea500bacd
7 changed files with 64 additions and 26 deletions

View File

@@ -5,10 +5,12 @@
import {setContext} from 'svelte';
import {goto} from '$app/navigation';
import {base} from "$app/paths";
import {toast} from "svelte-sonner";
let {data, children}: LayoutProps = $props();
console.log('Received User Data: ', data.user);
if (!data.user.is_verified) {
toast.info("Your account requires verification. Redirecting...");
goto(base + '/login/verify')
}
setContext('user', () => data.user);

View File

@@ -71,9 +71,9 @@
{show().overview}
</p>
</div>
<div class="h-full flex-auto rounded-xl bg-muted/50 p-4">
<div class="h-full flex-auto rounded-xl bg-muted/50 p-4 flex flex-col items-center justify-center gap-2">
{#if user().is_superuser}
<DownloadSeasonDialog {show}/>
<DownloadSeasonDialog show={show()}/>
{/if}
<RequestSeasonDialog show={show()}/>
</div>

View File

@@ -14,6 +14,7 @@
import {goto} from '$app/navigation';
import {base} from '$app/paths';
import AddShowCard from '$lib/components/add-show-card.svelte';
import {toast} from 'svelte-sonner';
let searchTerm: string = $state('');
let metadataProvider: string = $state('tmdb');
@@ -26,12 +27,30 @@
let url = new URL(env.PUBLIC_API_URL + '/tv/search');
url.searchParams.append('query', searchTerm);
url.searchParams.append('metadata_provider', metadataProvider);
const response = await fetch(url, {
method: 'GET',
credentials: 'include'
});
results = await response.json();
toast.info(`Searching for "${searchTerm}" using ${metadataProvider.toUpperCase()}...`);
try {
const response = await fetch(url, {
method: 'GET',
credentials: 'include'
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Search failed: ${response.status} ${errorText || response.statusText}`);
}
results = await response.json();
if (results && results.length > 0) {
toast.success(`Found ${results.length} result(s) for "${searchTerm}".`);
} else {
toast.info(`No results found for "${searchTerm}".`);
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred during search.';
console.error('Search error:', error);
toast.error(errorMessage);
results = null; // Clear previous results on error
}
} else {
toast.warning('Please enter a search term.');
results = null;
}
}