mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-19 05:54:06 +01:00
Refactor navigation bar component, add search functionality
This commit is contained in:
parent
b5bfccada8
commit
571ea13bf6
13
src/app/find/page.tsx
Normal file
13
src/app/find/page.tsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
|
export default function Find(){
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const query = searchParams.get('query');
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{query}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ import { cn } from "@/lib/utils";
|
|||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { ThemeToggle } from "@/components/theme-toggle";
|
import { ThemeToggle } from "@/components/theme-toggle";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
import {
|
import {
|
||||||
NavigationMenu,
|
NavigationMenu,
|
||||||
NavigationMenuContent,
|
NavigationMenuContent,
|
||||||
@ -134,6 +135,7 @@ export function NavigationBar() {
|
|||||||
const user = session?.user;
|
const user = session?.user;
|
||||||
const [sessionLoaded, setSessionLoaded] = React.useState(false);
|
const [sessionLoaded, setSessionLoaded] = React.useState(false);
|
||||||
const [searchActive, setSearchActive] = React.useState(false);
|
const [searchActive, setSearchActive] = React.useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!loading) {
|
if (!loading) {
|
||||||
@ -141,6 +143,14 @@ export function NavigationBar() {
|
|||||||
}
|
}
|
||||||
}, [loading]);
|
}, [loading]);
|
||||||
|
|
||||||
|
const handleKeyDown = (k: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
// check for "Enter"
|
||||||
|
if (k.key === 'Enter') {
|
||||||
|
const query = (k.target as HTMLInputElement).value.trim();
|
||||||
|
router.push(`/find?query=${encodeURIComponent(query)}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const businessComponents = [
|
const businessComponents = [
|
||||||
{
|
{
|
||||||
title: "Businesses",
|
title: "Businesses",
|
||||||
@ -258,17 +268,12 @@ export function NavigationBar() {
|
|||||||
{/* search bar's input */}
|
{/* search bar's input */}
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search..."
|
placeholder="Enter business name..."
|
||||||
className={cn(
|
className={cn(
|
||||||
"ml-2 border rounded-md px-2 py-1 transition-all duration-300 ease-in-out ",
|
"ml-2 border rounded-md px-2 py-1 transition-all duration-300 ease-in-out ",
|
||||||
searchActive ? "w-48 opacity-100" : "w-0 opacity-0"
|
searchActive ? "w-48 opacity-100" : "w-0 opacity-0"
|
||||||
)}
|
)}
|
||||||
onKeyDown={(k) => {
|
onKeyDown={handleKeyDown}
|
||||||
// when open search bar and hit enter
|
|
||||||
if(k.key == "Enter"){
|
|
||||||
console.log((k.target as HTMLInputElement).value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</NavigationMenuItem>
|
</NavigationMenuItem>
|
||||||
</NavigationMenuList>
|
</NavigationMenuList>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user