11'use client' ;
22
3- import React , { useEffect , useState } from 'react' ;
4- import Image from 'next/image' ;
5- import Link from 'next/link' ;
6- import { usePathname } from 'next/navigation' ;
7- import { useMetaKeyPress } from '@/hooks/use-meta-key-press' ;
83import { Session } from 'next-auth' ;
94import { signIn , signOut , useSession } from 'next-auth/react' ;
5+ import Image from 'next/image' ;
6+ import Link from 'next/link' ;
7+ import { usePathname , useRouter } from 'next/navigation' ;
108import {
119 Avatar ,
1210 Button ,
13- CommandDialog ,
14- CommandEmpty ,
15- CommandGroup ,
16- CommandInput ,
17- CommandItem ,
18- CommandList ,
11+ Dialog ,
1912 Divider ,
2013 IconButton ,
2114 Popover ,
15+ SearchInput ,
2216 Spinner ,
2317 Text ,
2418} from 'opub-ui' ;
19+ import React , { useEffect , useState } from 'react' ;
2520
21+ import { Icons } from '@/components/icons' ;
2622import { useDashboardStore } from '@/config/store' ;
2723import { GraphQL } from '@/lib/api' ;
28- import { Icons } from '@/components/icons' ;
2924import { UserDetailsQryDoc } from '../[entityType]/[entitySlug]/schema' ;
3025import { allOrganizationsListingDoc } from '../[entityType]/schema' ;
3126import Sidebar from './sidebar' ;
@@ -39,15 +34,13 @@ const profileLinks = [
3934
4035export function MainNav ( { hideSearch = false } ) {
4136 const pathname = usePathname ( ) ;
37+ const router = useRouter ( ) ;
38+ const [ isOpen , setIsOpen ] = useState ( false ) ;
4239
4340 const [ isLoggingOut , setIsLoggingOut ] = React . useState ( false ) ;
44- const searchRef = React . useRef < HTMLInputElement > ( null ) ;
4541 const { data : session , status } = useSession ( ) ;
46- const [ commandOpen , setCommandOpen ] = React . useState ( false ) ;
47- const { setUserDetails, setAllEntityDetails, userDetails, allEntityDetails } =
48- useDashboardStore ( ) ;
42+ const { setUserDetails, setAllEntityDetails } = useDashboardStore ( ) ;
4943
50- useMetaKeyPress ( 'k' , ( ) => setCommandOpen ( ( e ) => ! e ) ) ;
5144
5245 async function keycloakSessionLogOut ( ) {
5346 try {
@@ -125,6 +118,13 @@ export function MainNav({ hideSearch = false }) {
125118 } ,
126119 ] ;
127120
121+ const handleSearch = ( value : string ) => {
122+ if ( value ) {
123+ setIsOpen ( false ) ;
124+
125+ router . push ( `/datasets?query=${ encodeURIComponent ( value ) } ` ) ;
126+ }
127+ } ;
128128 return (
129129 < nav className = "p-4 lg:p-6" >
130130 < div className = "flex items-center justify-between gap-4 " >
@@ -170,30 +170,29 @@ export function MainNav({ hideSearch = false }) {
170170
171171 < div className = "flex items-center gap-8" >
172172 < div className = "relative hidden lg:block" >
173- < IconButton
174- size = "slim"
175- icon = { Icons . search }
176- withTooltip
177- color = "onBgDefault"
178- onClick = { ( ) => setCommandOpen ( true ) }
179- >
180- Search
181- </ IconButton >
182-
183- < CommandDialog open = { commandOpen } onOpenChange = { setCommandOpen } >
184- < CommandInput placeholder = "search..." />
185- < CommandList >
186- < CommandEmpty > No results found</ CommandEmpty >
187- < CommandGroup heading = "Suggestions" >
188- < CommandItem >
189- < Link href = "/datasets" > Explore Datasets</ Link >
190- </ CommandItem >
191- < CommandItem >
192- < Link href = "/dashboard" > Go to User Dashboard</ Link >
193- </ CommandItem >
194- </ CommandGroup >
195- </ CommandList >
196- </ CommandDialog >
173+ < Dialog open = { isOpen } onOpenChange = { setIsOpen } >
174+ < Dialog . Trigger >
175+ < IconButton
176+ size = "slim"
177+ icon = { Icons . search }
178+ withTooltip
179+ color = "onBgDefault"
180+ onClick = { ( ) => setIsOpen ( true ) }
181+ >
182+ Search
183+ </ IconButton >
184+ </ Dialog . Trigger >
185+ < Dialog . Content title = { 'Search' } >
186+ < div className = "p-3" >
187+ < SearchInput
188+ onSubmit = { handleSearch }
189+ label = { '' }
190+ placeholder = "Search for any data"
191+ name = { '' }
192+ />
193+ </ div >
194+ </ Dialog . Content >
195+ </ Dialog >
197196 </ div >
198197
199198 < div className = "flex items-center gap-5" >
0 commit comments