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
11
} from "../ui/form";
12
12
import { Input } from "../ui/input";
13
13
14
14
+
const oneEmoji = z
15
15
+
.string()
16
16
+
.refine((val) => val.length === 0 || [...val].length === 1, {
17
17
+
error: "Please enter a single emoji",
18
18
+
});
19
19
+
20
20
+
const gridDimension = (dir: "row" | "column") =>
21
21
+
z.coerce.number<number>().min(2, { error: `Minimum 2 ${dir}s` });
22
22
+
14
23
type FormData = z.infer<typeof formSchema>;
15
24
const formSchema = z.object({
16
16
-
width: z.coerce.number<number>(),
17
17
-
height: z.coerce.number<number>(),
18
18
-
variants: z.array(z.string()).min(2).max(4),
25
25
+
width: gridDimension("column"),
26
26
+
height: gridDimension("row"),
27
27
+
variants: z.array(oneEmoji).min(2).max(4),
19
28
});
20
29
21
30
interface Props {