fix: improved searchbar
This commit is contained in:
parent
211b8ceb3f
commit
5d4a7ae552
|
@ -1,7 +1,22 @@
|
||||||
|
import {redirect} from "next/navigation"
|
||||||
|
import { headers } from 'next/headers'
|
||||||
import Feed from "@/components/Feed"
|
import Feed from "@/components/Feed"
|
||||||
import SearchBar from "@/components/SearchBar"
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchBar />
|
<SearchBar />
|
||||||
|
@ -10,17 +25,17 @@ export default function Home() {
|
||||||
<Feed
|
<Feed
|
||||||
title="Latest from the community"
|
title="Latest from the community"
|
||||||
icon={'paper-icon'}
|
icon={'paper-icon'}
|
||||||
className="w-[calc(33%-16px)] max-w-md"
|
className="w-[calc(33%-20px)] max-w-md"
|
||||||
/>
|
/>
|
||||||
<Feed
|
<Feed
|
||||||
title="Rising Posts"
|
title="Rising Posts"
|
||||||
icon={'trend-up-icon'}
|
icon={'trend-up-icon'}
|
||||||
className="w-[calc(33%-16px)] max-w-md"
|
className="w-[calc(33%-20px)] max-w-md"
|
||||||
/>
|
/>
|
||||||
<Feed
|
<Feed
|
||||||
title="Top Posts"
|
title="Top Posts"
|
||||||
icon={'top-arrow-icon'}
|
icon={'top-arrow-icon'}
|
||||||
className="w-[calc(33%-16px)] max-w-md"
|
className="w-[calc(33%-20px)] max-w-md"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Feed
|
<Feed
|
||||||
|
|
|
@ -64,13 +64,6 @@ const SearchBar = ({ }: Props) => {
|
||||||
|
|
||||||
const isActive = results.length > 0 || dirtyInput
|
const isActive = results.length > 0 || dirtyInput
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!dirtyInput && searchParams.get("q") && searchParams.get("q") !== "") {
|
|
||||||
handleSearch()
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`w-full mt-8 p-4 border-2 ${
|
className={`w-full mt-8 p-4 border-2 ${
|
||||||
|
@ -104,7 +97,7 @@ const SearchBar = ({ }: Props) => {
|
||||||
: "w-full p-2"
|
: "w-full p-2"
|
||||||
}`}
|
}`}
|
||||||
placeholder={
|
placeholder={
|
||||||
isActive
|
!isActive
|
||||||
? "Search for web3 news from the community"
|
? "Search for web3 news from the community"
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue