mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Fixing return form data.
This commit is contained in:
parent
0c295c66b4
commit
fb84c6da90
5 changed files with 30 additions and 43 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
export let pageSize: number; // Reactive, bind
|
export let pageSize: number; // Reactive, bind
|
||||||
export let page: number = 1; // Reactive, bind
|
export let page: number = 1; // Reactive, bind
|
||||||
export let totalItems: number;
|
export let totalItems: number;
|
||||||
|
export let showItemsLeft = false;
|
||||||
export let pageSizeInputDisabled: boolean = false;
|
export let pageSizeInputDisabled: boolean = false;
|
||||||
export let pageSizes: ReadonlyArray<Number> = [10];
|
export let pageSizes: ReadonlyArray<Number> = [10];
|
||||||
export let forwardText: string;
|
export let forwardText: string;
|
||||||
|
|
@ -74,9 +75,11 @@
|
||||||
<p>
|
<p>
|
||||||
Page {page || 1} of {totalPages || 1}
|
Page {page || 1} of {totalPages || 1}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
{#if showItemsLeft}
|
||||||
{itemsLeft} Item{itemsLeft > 1 || itemsLeft === 0 ? 's' : ''} Left
|
<p>
|
||||||
</p>
|
{itemsLeft} Item{itemsLeft > 1 || itemsLeft === 0 ? 's' : ''} Left
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
<div style="display: flex; gap: 2rem;">
|
<div style="display: flex; gap: 2rem;">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -107,17 +110,13 @@
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.container {
|
.container {
|
||||||
display: grid;
|
display: flex;
|
||||||
grid-template-columns: repeat(4, 1fr);
|
flex: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
margin: 3rem 0;
|
margin: 3rem 0;
|
||||||
|
|
||||||
@media (max-width: 640px) {
|
|
||||||
grid-template-columns: repeat(2, 1fr);
|
|
||||||
grid-template-rows: repeat(2, 1fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
|
@ -131,23 +130,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* .list-container :global(.list-box) {
|
|
||||||
height: 100%;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.list-container :global(.list-options) {
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
.list-container :global(.active) {
|
|
||||||
display: flex;
|
|
||||||
gap: 1rem;
|
|
||||||
padding: 1rem;
|
|
||||||
} */
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
/* min-width: 50px; */
|
|
||||||
&[aria-current],
|
&[aria-current],
|
||||||
&.current {
|
&.current {
|
||||||
color: black; // TODO: Fix these colors
|
color: black; // TODO: Fix these colors
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { boredState } from '$lib/stores/boredState';
|
import { boredState } from '$lib/stores/boredState';
|
||||||
|
|
||||||
export let form: ActionData;
|
export let form: ActionData;
|
||||||
|
console.log('form data', form?.data);
|
||||||
const errors = form?.errors;
|
const errors = form?.errors;
|
||||||
let submitting = $boredState?.loading;
|
let submitting = $boredState?.loading;
|
||||||
let minAge = +form?.data?.minAge || 1;
|
let minAge = +form?.data?.minAge || 1;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ export function convertToSavedGame(game: GameType | SavedGameType): SavedGameTyp
|
||||||
|
|
||||||
export function mapSavedGameToGame(game: SavedGameType): GameType {
|
export function mapSavedGameToGame(game: SavedGameType): GameType {
|
||||||
const { id, name, thumb_url, players, playtime } = game;
|
const { id, name, thumb_url, players, playtime } = game;
|
||||||
|
console.log({ id, name, thumb_url, players, playtime });
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
|
|
@ -17,26 +17,24 @@ export const saved_game_schema = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://github.com/colinhacks/zod/discussions/330
|
// https://github.com/colinhacks/zod/discussions/330
|
||||||
// function IntegerString
|
function IntegerString
|
||||||
// <schema extends (ZodNumber | ZodOptional<ZodNumber>)>
|
<schema extends (ZodNumber | ZodOptional<ZodNumber>)>
|
||||||
// (schema: schema)
|
(schema: schema)
|
||||||
// {
|
{
|
||||||
// return (
|
return (
|
||||||
// z.preprocess((value) => (
|
z.preprocess((value) => (
|
||||||
// ( (typeof value === "string") ? parseInt(value, 10)
|
( (typeof value === "string") ? parseInt(value, 10)
|
||||||
// : (typeof value === "number") ? value
|
: (typeof value === "number") ? value
|
||||||
// : undefined
|
: undefined
|
||||||
// )), schema)
|
)), schema)
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// minPlayers: IntegerString(z.number().min(1).max(50).optional());
|
|
||||||
|
|
||||||
export const search_schema = z.object({
|
export const search_schema = z.object({
|
||||||
name: z.string().trim().optional(),
|
name: z.string().trim().optional(),
|
||||||
minAge: z.preprocess((a) => parseInt(z.string().parse(a), 10), z.number().min(1).max(120).optional()),
|
minAge: IntegerString(z.number().min(1).max(120).optional()),
|
||||||
minPlayers: z.preprocess((a) => parseInt(z.string().parse(a), 10), z.number().min(1).max(50).optional()),
|
minPlayers: IntegerString(z.number().min(1).max(50).optional()),
|
||||||
maxPlayers: z.preprocess((a) => parseInt(z.string().parse(a), 10), z.number().min(1).max(50).optional()),
|
maxPlayers: IntegerString(z.number().min(1).max(50).optional()),
|
||||||
exactMinAge: z.preprocess((a) => Boolean(a), z.boolean().optional()),
|
exactMinAge: z.preprocess((a) => Boolean(a), z.boolean().optional()),
|
||||||
exactMinPlayers: z.preprocess((a) => Boolean(a), z.boolean().optional()),
|
exactMinPlayers: z.preprocess((a) => Boolean(a), z.boolean().optional()),
|
||||||
exactMaxPlayers: z.preprocess((a) => Boolean(a), z.boolean().optional())
|
exactMaxPlayers: z.preprocess((a) => Boolean(a), z.boolean().optional())
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ export const actions: Actions = {
|
||||||
const random = formData?.random === 'on';
|
const random = formData?.random === 'on';
|
||||||
|
|
||||||
if (random) {
|
if (random) {
|
||||||
|
console.log('Random');
|
||||||
queryParams.random = random;
|
queryParams.random = random;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|
@ -82,6 +83,8 @@ export const actions: Actions = {
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof ZodError) {
|
if (error instanceof ZodError) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
const { fieldErrors: errors } = error.flatten();
|
const { fieldErrors: errors } = error.flatten();
|
||||||
return invalid(400, { data: formData, errors });
|
return invalid(400, { data: formData, errors });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue