diff --git a/app/_components/Header.tsx b/app/_components/Header.tsx index ada640d..5330438 100644 --- a/app/_components/Header.tsx +++ b/app/_components/Header.tsx @@ -11,39 +11,37 @@ import { useSearchParams } from "next/navigation"; import TimePopover from "@/app/_components/TimePopover"; import { parseParam } from "@/app/_lib/utils"; -const defaultValues = { - subreddit: "", -}; - type Values = { - subreddit: string; + search: string; }; export default function Header() { const params = useParams(); const subreddit = parseParam(params.subreddit) || DEFAULT_SUBREDDIT; - const username = params.username; + const username = parseParam(params.username) || ""; const searchParams = useSearchParams(); const time = searchParams.get("t"); const form = useForm({ - defaultValues, + defaultValues: { + search: "", + }, }); const { push } = useRouter(); useEffect(() => { if (username) { - form.reset(defaultValues); + form.reset({ search: username }); } else { - form.reset({ subreddit }); + form.reset({ search: subreddit }); } }, [form, subreddit, username]); const handleOnSubmit = (values: Values) => { - push(`/r/${values.subreddit}/hot`); + push(`/r/${values.search}/hot`); }; return ( -
+
diff --git a/tests/index.spec.ts b/tests/index.spec.ts index 80c1cbc..3793a20 100644 --- a/tests/index.spec.ts +++ b/tests/index.spec.ts @@ -17,7 +17,7 @@ test.describe("home", () => { }); test("Search input", async ({ page, baseURL }) => { - const input = page.getByTestId("subreddit-input"); + const input = page.getByTestId("search-input"); await input.fill("pics"); await page.keyboard.press("Enter");