tangled
alpha
login
or
join now
emarref.net
/
ticks
0
fork
atom
A daily game
0
fork
atom
overview
issues
pulls
pipelines
Improve preferences validation
Malcolm Fell
5 months ago
2100123e
9289a371
+12
-3
1 changed file
expand all
collapse all
unified
split
src
components
game
preferences-form.tsx
+12
-3
src/components/game/preferences-form.tsx
···
11
} from "../ui/form";
12
import { Input } from "../ui/input";
13
0
0
0
0
0
0
0
0
0
14
type FormData = z.infer<typeof formSchema>;
15
const formSchema = z.object({
16
-
width: z.coerce.number<number>(),
17
-
height: z.coerce.number<number>(),
18
-
variants: z.array(z.string()).min(2).max(4),
19
});
20
21
interface Props {
···
11
} from "../ui/form";
12
import { Input } from "../ui/input";
13
14
+
const oneEmoji = z
15
+
.string()
16
+
.refine((val) => val.length === 0 || [...val].length === 1, {
17
+
error: "Please enter a single emoji",
18
+
});
19
+
20
+
const gridDimension = (dir: "row" | "column") =>
21
+
z.coerce.number<number>().min(2, { error: `Minimum 2 ${dir}s` });
22
+
23
type FormData = z.infer<typeof formSchema>;
24
const formSchema = z.object({
25
+
width: gridDimension("column"),
26
+
height: gridDimension("row"),
27
+
variants: z.array(oneEmoji).min(2).max(4),
28
});
29
30
interface Props {