diff --git a/src/lib/schema/browse.ts b/src/lib/schema/browse.ts index ceaa450..ef5b313 100644 --- a/src/lib/schema/browse.ts +++ b/src/lib/schema/browse.ts @@ -2,22 +2,24 @@ import { z } from 'zod'; export const schema = z.object({ state: z - .enum([ - '', - 'Unknown', - 'Unreleased', - 'Ongoing', - 'Requested', - 'Indexed', - 'Scraped', - 'Downloaded', - 'Symlinked', - 'Completed', - 'PartiallyCompleted', - 'Failed' - ]) - .default(''), - type: z.enum(['movie', 'show', 'movie,show']).default('movie,show'), + .array( + z.enum([ + '', + 'Unknown', + 'Unreleased', + 'Ongoing', + 'Requested', + 'Indexed', + 'Scraped', + 'Downloaded', + 'Symlinked', + 'Completed', + 'PartiallyCompleted', + 'Failed' + ]) + ) + .default([]), + type: z.array(z.enum(['movie', 'show'])).default(['movie', 'show']), sort: z.enum(['date_desc', 'date_asc', 'title_asc', 'title_desc']).default('date_desc') }); @@ -38,8 +40,7 @@ export const states = { export const types = { movie: 'Movies', - show: 'Shows', - 'movie,show': 'Movies & Shows' + show: 'Shows' }; export const sortOptions = { diff --git a/src/routes/browse/+page.svelte b/src/routes/browse/+page.svelte index 133dd79..4263d42 100644 --- a/src/routes/browse/+page.svelte +++ b/src/routes/browse/+page.svelte @@ -1,4 +1,6 @@ @@ -97,10 +138,11 @@ selected={selectedState} onSelectedChange={(s) => { if (s) { - $formData.state = s.value; + $formData.state = mapSelectedStates(s); handleFilterChange(); } }} + multiple > @@ -123,10 +165,11 @@ selected={selectedType} onSelectedChange={(s) => { if (s) { - $formData.type = s.value; + $formData.type = mapSelectedTypes(s); handleFilterChange(); } }} + multiple > @@ -187,10 +230,11 @@ {/each} - + { diff --git a/src/routes/browse/+page.ts b/src/routes/browse/+page.ts index e6bbfcc..898d247 100644 --- a/src/routes/browse/+page.ts +++ b/src/routes/browse/+page.ts @@ -1,14 +1,33 @@ import { superValidate } from 'sveltekit-superforms/client'; import { schema } from '$lib/schema/browse'; -import { ItemsService } from '$lib/client'; +import { ItemsService, type States } from '$lib/client'; import { zod } from 'sveltekit-superforms/adapters'; import type { PageLoad } from '../$types'; import type { RivenGetItemsResponse } from '$lib/types'; -export const load = (async () => { +export const load = (async ({ url }) => { const form = await superValidate({}, zod(schema)); - const page = 1; - const limit = 12; + let page = 1; + const limit = 24; + + if (url.searchParams.has('page')) { + page = parseInt(url.searchParams.get('page') as string); + } + if (url.searchParams.has('sort')) { + form.data.sort = url.searchParams.get('sort') as + | 'date_desc' + | 'date_asc' + | 'title_asc' + | 'title_desc'; + } + if (url.searchParams.has('type')) { + form.data.type = url.searchParams.get('type')?.split(',') as ['movie', 'show']; + } + if (url.searchParams.has('state')) { + form.data.state = url.searchParams.get('state')?.split(',') as States[]; + } else { + form.data.state = ['']; + } async function getItems(): Promise { try { @@ -17,8 +36,8 @@ export const load = (async () => { page, sort: form.data.sort, limit, - type: form.data.type, - states: form.data.state + type: form.data.type.join(','), + states: form.data.state.join(',') } }); diff --git a/src/routes/summary/+page.svelte b/src/routes/summary/+page.svelte index 3ccf9fc..08d7529 100644 --- a/src/routes/summary/+page.svelte +++ b/src/routes/summary/+page.svelte @@ -19,23 +19,23 @@ { title: 'Total Items', value: data.stats?.total_items || 0, - refTo: '/library' + refTo: '/browse' }, { title: 'Total Movies', value: data.stats?.total_movies || 0, - refTo: '/library?types=movie' + refTo: '/browse?type=movie' }, { title: 'Total Shows', value: data.stats?.total_shows || 0, - refTo: '/library?types=show' + refTo: '/browse?type=show' }, { title: 'Incomplete Items', value: data.stats?.incomplete_items || 0, refTo: - '/library?states=Unknown%2CRequested%2CIndexed%2CScraped%2CDownloaded%2CSymlinked%2CFailed%2CPartiallyCompleted' + '/browse?state=Unknown%2CRequested%2CIndexed%2CScraped%2CDownloaded%2CSymlinked%2CFailed%2CPartiallyCompleted' } ]; @@ -218,9 +218,7 @@ {data.stats.states[state]} - - See items - + See items {/each}
{data.stats.states[state]}