feat: integrate toast notifications for error handling and success messages in dialogs

This commit is contained in:
maxDorninger
2025-05-24 19:59:36 +02:00
parent 84abc3e81d
commit 6513065ba8
5 changed files with 27 additions and 12 deletions

View File

@@ -1,13 +1,9 @@
<script lang="ts">
import {env} from '$env/dynamic/public';
import {Button, buttonVariants} from '$lib/components/ui/button/index.js';
import * as Dialog from '$lib/components/ui/dialog/index.js';
import {Input} from '$lib/components/ui/input';
import {Label} from '$lib/components/ui/label';
import * as Select from '$lib/components/ui/select/index.js';
import * as Tabs from '$lib/components/ui/tabs/index.js';
import * as Table from '$lib/components/ui/table/index.js';
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
import {toast} from 'svelte-sonner';
import type {PublicIndexerQueryResult} from '$lib/types.js';
import {convertTorrentSeasonRangeToIntegerRange, getFullyQualifiedShowName} from '$lib/utils';
@@ -41,16 +37,19 @@
const errorMessage = `Failed to download torrent for show ${show.id} and season ${selectedSeasonNumber}: ${response.statusText}`;
console.error(errorMessage);
torrentsError = errorMessage;
toast.error(errorMessage);
return false;
}
const data: PublicIndexerQueryResult[] = await response.json();
console.log('Downloading torrent:', data);
toast.success('Torrent download started successfully!');
return true;
} catch (err) {
const errorMessage = `Error downloading torrent: ${err instanceof Error ? err.message : 'An unknown error occurred'}`;
console.error(errorMessage);
toast.error(errorMessage);
return false;
}
}
@@ -84,17 +83,24 @@
const errorMessage = `Failed to fetch torrents for show ${show.id} and season ${selectedSeasonNumber}: ${response.statusText}`;
console.error(errorMessage);
torrentsError = errorMessage;
toast.error(errorMessage);
return [];
}
const data: PublicIndexerQueryResult[] = await response.json();
console.log('Fetched torrents:', data);
if (data.length > 0) {
toast.success(`Found ${data.length} torrents.`);
} else {
toast.info('No torrents found for your query.');
}
return data;
} catch (err) {
const errorMessage = `Error fetching torrents: ${err instanceof Error ? err.message : 'An unknown error occurred'}`;
console.error(errorMessage);
torrentsError = errorMessage;
toast.error(errorMessage);
return [];
} finally {
isLoadingTorrents = false;
@@ -198,8 +204,7 @@
torrentsError = null;
torrents = [];
try {
const fetchedTorrents = await getTorrents(selectedSeasonNumber, true);
torrents = fetchedTorrents;
torrents = await getTorrents(selectedSeasonNumber, true);
} catch (error) {
console.log(error);
} finally {
@@ -301,4 +306,4 @@
{/if}
</div>
</Dialog.Content>
</Dialog.Root>
</Dialog.Root>

View File

@@ -197,3 +197,5 @@
</Card.Root>
</Tabs.Content>
</Tabs.Root>

View File

@@ -7,6 +7,7 @@
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
import type {PublicShow, Quality, CreateSeasonRequest} from '$lib/types.js';
import {getFullyQualifiedShowName, getTorrentQualityString} from '$lib/utils.js';
import {toast} from 'svelte-sonner';
let {show}: { show: PublicShow } = $props();
@@ -53,14 +54,16 @@
selectedSeasonsIds = undefined;
minQuality = undefined;
wantedQuality = undefined;
// Optionally: add a success toast/notification here
toast.success('Season request submitted successfully!');
} else {
const errorData = await response.json().catch(() => ({message: response.statusText}));
submitRequestError = `Failed to submit request: ${errorData.message || response.statusText}`;
toast.error(submitRequestError);
console.error('Failed to submit request', response.statusText, errorData);
}
} catch (error) {
submitRequestError = `Error submitting request: ${error instanceof Error ? error.message : String(error)}`;
toast.error(submitRequestError);
console.error('Error submitting request:', error);
} finally {
isSubmittingRequest = false;
@@ -159,4 +162,5 @@
</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
</Dialog.Root>

View File

@@ -128,4 +128,4 @@
{/if}
{/each}
</Table.Body>
</Table.Root>
</Table.Root>