song type schema stuff
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
import { addAllToQueue, playAllNext } from "$lib/player/player.svelte";
|
import { addAllToQueue, playAllNext } from "$lib/player/player.svelte";
|
||||||
import { trackFromSongRow } from "$lib/player/types";
|
import { trackFromSongRow } from "$lib/player/types";
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types";
|
||||||
import { SearchParamsSchema } from "./schema";
|
import { SearchParamsSchemaClient } from "./schema";
|
||||||
|
|
||||||
const params = useSearchParams(SearchParamsSchema, {
|
const params = useSearchParams(SearchParamsSchemaClient, {
|
||||||
pushHistory: false,
|
pushHistory: false,
|
||||||
showDefaults: false,
|
showDefaults: false,
|
||||||
});
|
});
|
||||||
@@ -135,7 +135,8 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
{#if data.songRows.length > 0}
|
{#if data.songRows.length > 0}
|
||||||
<div class="mt-6 flex flex-wrap gap-2">
|
<div class="mt-6 flex flex-col gap-2">
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
@@ -161,9 +162,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="mt-6 text-lg font-semibold">Songs</h2>
|
<div class="flex items-center gap-4">
|
||||||
|
<h2 class="text-lg font-semibold">Songs</h2>
|
||||||
|
<span>{data.songRows.length}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul class="mt-3 space-y-2">
|
<ul class="space-y-2">
|
||||||
{#each data.songRows as r (r.annSongId)}
|
{#each data.songRows as r (r.annSongId)}
|
||||||
<li>
|
<li>
|
||||||
<SongEntry
|
<SongEntry
|
||||||
@@ -178,6 +182,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
{:else if Object.values(params).some((val) => (Array.isArray(val) && val.length > 0) || (typeof val === "string" && val.trim() !== "") || typeof val === "number")}
|
{:else if Object.values(params).some((val) => (Array.isArray(val) && val.length > 0) || (typeof val === "string" && val.trim() !== "") || typeof val === "number")}
|
||||||
<p class="mt-4 text-sm text-muted-foreground">
|
<p class="mt-4 text-sm text-muted-foreground">
|
||||||
No songs found matching your criteria.
|
No songs found matching your criteria.
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import type { SongFilters } from "$lib/db/client-db";
|
import type { SongFilters } from "$lib/db/client-db";
|
||||||
import { db, ensureSeeded, getSongsWithFilters } from "$lib/db/client-db";
|
import { db, ensureSeeded, getSongsWithFilters } from "$lib/db/client-db";
|
||||||
import type { PageLoad } from "./$types";
|
import type { PageLoad } from "./$types";
|
||||||
import { SearchParamsSchema } from "./schema";
|
import { SearchParamsSchemaServer } from "./schema";
|
||||||
|
|
||||||
export const load: PageLoad = async ({ url, fetch, depends }) => {
|
export const load: PageLoad = async ({ url, fetch, depends }) => {
|
||||||
depends("clientdb:songs");
|
depends("clientdb:songs");
|
||||||
|
|
||||||
const parsed = SearchParamsSchema.safeParse(
|
const parsed = SearchParamsSchemaServer.safeParse(
|
||||||
Object.fromEntries(url.searchParams.entries()),
|
Object.fromEntries(url.searchParams.entries()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,12 @@ export const SearchParamsSchema = z.object({
|
|||||||
anime: z.string().optional().default(""),
|
anime: z.string().optional().default(""),
|
||||||
gpm: z.coerce.number().int().optional().default(0),
|
gpm: z.coerce.number().int().optional().default(0),
|
||||||
gpx: z.coerce.number().int().optional().default(100),
|
gpx: z.coerce.number().int().optional().default(100),
|
||||||
songType: z.coerce.number().int().optional().default(0),
|
});
|
||||||
|
|
||||||
|
export const SearchParamsSchemaClient = SearchParamsSchema.extend({
|
||||||
|
songType: z.string().optional().default("0"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SearchParamsSchemaServer = SearchParamsSchema.extend({
|
||||||
|
songType: z.coerce.number().int().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user