From af4b2fb8dc54f0a8f5f8e176d3b42906d3b704ec Mon Sep 17 00:00:00 2001 From: Davide Marcoli <69892203+davidemarcoli@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:24:52 +0100 Subject: [PATCH] fix: update default state to 'All' and filter valid states in browse logic (#171) --- src/lib/schema/browse.ts | 6 +++--- src/routes/browse/+page.svelte | 2 ++ src/routes/browse/+page.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/schema/browse.ts b/src/lib/schema/browse.ts index ef5b313..276b2d0 100644 --- a/src/lib/schema/browse.ts +++ b/src/lib/schema/browse.ts @@ -4,7 +4,7 @@ export const schema = z.object({ state: z .array( z.enum([ - '', + 'All', 'Unknown', 'Unreleased', 'Ongoing', @@ -18,13 +18,13 @@ export const schema = z.object({ 'Failed' ]) ) - .default([]), + .default(['All']), type: z.array(z.enum(['movie', 'show'])).default(['movie', 'show']), sort: z.enum(['date_desc', 'date_asc', 'title_asc', 'title_desc']).default('date_desc') }); export const states = { - '': 'Any State', + All: 'Any State', Unknown: 'Unknown', Unreleased: 'Unreleased', Ongoing: 'Ongoing', diff --git a/src/routes/browse/+page.svelte b/src/routes/browse/+page.svelte index 4263d42..f806e18 100644 --- a/src/routes/browse/+page.svelte +++ b/src/routes/browse/+page.svelte @@ -40,11 +40,13 @@ params .get('state') ?.split(',') + .filter((state) => state in states) .map((state) => state as keyof typeof states) || $formData.state; $formData.type = params .get('type') ?.split(',') + .filter((type) => type in types) .map((type) => type as keyof typeof types) || $formData.type; $formData.sort = (params.get('sort') as keyof typeof sortOptions) || $formData.sort; } diff --git a/src/routes/browse/+page.ts b/src/routes/browse/+page.ts index 898d247..21352d3 100644 --- a/src/routes/browse/+page.ts +++ b/src/routes/browse/+page.ts @@ -26,7 +26,7 @@ export const load = (async ({ url }) => { if (url.searchParams.has('state')) { form.data.state = url.searchParams.get('state')?.split(',') as States[]; } else { - form.data.state = ['']; + form.data.state = ['All']; } async function getItems(): Promise {