From 5d4a7ae552a342ad9947f6937f549773c515f294 Mon Sep 17 00:00:00 2001 From: Juan Di Toro Date: Wed, 22 Nov 2023 12:59:45 +0100 Subject: [PATCH] fix: improved searchbar --- src/app/page.tsx | 23 +++++++++++++++++++---- src/components/SearchBar.tsx | 9 +-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 5792d71..d141f6f 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,22 @@ +import {redirect} from "next/navigation" +import { headers } from 'next/headers' import Feed from "@/components/Feed" import SearchBar from "@/components/SearchBar" -export default function Home() { +type Props = { + searchParams?: { + q?: string | undefined + }; +} + +export default function Home({searchParams}: Props) { + const headerList = headers() + const referer = headerList.get("referer") + + if(!referer && searchParams?.q) { + redirect(`/search?q=${searchParams.q}`) + } + return ( <> @@ -10,17 +25,17 @@ export default function Home() { { const isActive = results.length > 0 || dirtyInput - useEffect(() => { - if (!dirtyInput && searchParams.get("q") && searchParams.get("q") !== "") { - handleSearch() - } - }, []) - - return (
{ : "w-full p-2" }`} placeholder={ - isActive + !isActive ? "Search for web3 news from the community" : undefined }