mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-21 00:05:36 +02:00
create function for displaying query result toasts to reduce code duplication
This commit is contained in:
@@ -99,3 +99,10 @@ export function formatSecondsToOptimalUnit(seconds: number): string {
|
||||
|
||||
return '0s';
|
||||
}
|
||||
|
||||
export function handleQueryNotificationToast(count: number = 0, query: string = "") {
|
||||
if (count > 0 && query.length > 0) toast.success(`Found ${count} ${count > 1 ? 'result' : 'results'} for search term "${query}".`);
|
||||
else if (count == 0) toast.info(`No results found for "${query}".`);
|
||||
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
import { base } from '$app/paths';
|
||||
import client from '$lib/api';
|
||||
import type { components } from '$lib/api/api';
|
||||
import {handleQueryNotificationToast} from "$lib/utils.ts";
|
||||
|
||||
let searchTerm: string = $state('');
|
||||
let metadataProvider: 'tmdb' | 'tvdb' = $state('tmdb');
|
||||
@@ -36,12 +37,11 @@
|
||||
})
|
||||
: await client.GET('/api/v1/movies/recommended');
|
||||
if (data && data.length > 0) {
|
||||
toast.success(`Found ${data.length} result(s) for "${query}".`);
|
||||
results = data as components['schemas']['MetaDataProviderSearchResult'][];
|
||||
} else {
|
||||
toast.info(`No results found for "${query}".`);
|
||||
results = null;
|
||||
}
|
||||
handleQueryNotificationToast(data?.length ?? 0, query)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import { resolve } from '$app/paths';
|
||||
import client from '$lib/api';
|
||||
import type { components } from '$lib/api/api';
|
||||
import {handleQueryNotificationToast} from "$lib/utils.ts";
|
||||
|
||||
onMount(() => {
|
||||
search('');
|
||||
@@ -36,12 +37,13 @@
|
||||
})
|
||||
: await client.GET('/api/v1/tv/recommended');
|
||||
if (results.data && results.data.length > 0) {
|
||||
toast.success(`Found ${results.data.length} result(s) for "${query}".`);
|
||||
handleQueryNotificationToast(results.data.length, query)
|
||||
data = results.data as components['schemas']['MetaDataProviderSearchResult'][];
|
||||
} else {
|
||||
toast.info(`No results found for "${query}".`);
|
||||
handleQueryNotificationToast(0, query)
|
||||
data = null;
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user