refactor: cleanup - schema edition

whole bunch of refactors (especially with schemas)
This commit is contained in:
trafficlunar 2025-04-12 17:01:16 +01:00
parent 626016d689
commit 2e4611520d
7 changed files with 40 additions and 36 deletions

View file

@ -40,7 +40,6 @@ export default async function MiiList({ searchParams, userId, where }: Props) {
: [];
const whereTags = tagFilter.length > 0 ? { tags: { hasEvery: tagFilter } } : undefined;
// If the mii list is on a user's profile, don't query for the username
const userInclude =
userId == null
? {

View file

@ -3,20 +3,13 @@
import { useState } from "react";
import { Icon } from "@iconify/react";
import { redirect } from "next/navigation";
import { z } from "zod";
const searchSchema = z
.string()
.trim()
.min(2)
.max(64)
.regex(/^[a-zA-Z0-9_]+$/);
import { nameSchema } from "@/lib/schemas";
export default function SearchBar() {
const [query, setQuery] = useState("");
const handleSearch = () => {
const result = searchSchema.safeParse(query);
const result = nameSchema.safeParse(query);
if (!result.success) redirect("/");
redirect(`/search?q=${query}`);

View file

@ -9,7 +9,7 @@ interface Props {
setTags: React.Dispatch<React.SetStateAction<string[]>>;
}
const tagRegex = /^[a-z-]*$/;
const tagRegex = /^[a-z0-9-_]*$/;
const predefinedTags = ["anime", "art", "cartoon", "celebrity", "games", "history", "meme", "movie", "oc", "tv"];
export default function TagSelector({ tags, setTags }: Props) {