mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-06-28 14:44:15 +00:00
refactor: cleanup - schema edition
whole bunch of refactors (especially with schemas)
This commit is contained in:
parent
626016d689
commit
2e4611520d
7 changed files with 40 additions and 36 deletions
|
|
@ -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
|
||||
? {
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue