Skip to content

Commit

Permalink
fix: update default state to 'All' and filter valid states in browse …
Browse files Browse the repository at this point in the history
…logic (#171)
  • Loading branch information
davidemarcoli authored Nov 6, 2024
1 parent dd9cf98 commit af4b2fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lib/schema/browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const schema = z.object({
state: z
.array(
z.enum([
'',
'All',
'Unknown',
'Unreleased',
'Ongoing',
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/routes/browse/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/browse/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RivenGetItemsResponse> {
Expand Down

0 comments on commit af4b2fb

Please sign in to comment.