File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed
src/components/databrowser Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 1+ import { useState } from "react"
12import { useDatabrowserStore } from "@/store"
23import { IconX } from "@tabler/icons-react"
34
@@ -6,14 +7,27 @@ import { Input } from "@/components/ui/input"
67
78export const SearchInput = ( ) => {
89 const { setSearchKey, search } = useDatabrowserStore ( )
10+ const [ state , setState ] = useState ( search . key )
11+
12+ const submit = ( value : string ) => {
13+ if ( value . trim ( ) !== "" && ! value . includes ( "*" ) ) value = `${ value } *`
14+ setSearchKey ( value )
15+ setState ( value )
16+ }
917
1018 return (
1119 < div className = "relative grow" >
1220 < Input
1321 placeholder = "Search"
1422 className = { "rounded-l-none border-zinc-300 font-normal" }
15- onChange = { ( e ) => setSearchKey ( e . target . value ) }
16- value = { search . key }
23+ onKeyDown = { ( e ) => {
24+ if ( e . key === "Enter" ) submit ( e . currentTarget . value )
25+ } }
26+ onChange = { ( e ) => {
27+ setState ( e . currentTarget . value )
28+ if ( e . currentTarget . value . trim ( ) === "" ) submit ( "" )
29+ } }
30+ value = { state }
1731 />
1832 { search . key && (
1933 < Button
Original file line number Diff line number Diff line change @@ -23,15 +23,7 @@ const KeysContext = createContext<
2323export const FETCH_KEYS_QUERY_KEY = "use-fetch-keys"
2424
2525export const KeysProvider = ( { children } : PropsWithChildren ) => {
26- const { search : searchState } = useDatabrowserStore ( )
27-
28- const search = useMemo (
29- ( ) => ( {
30- key : searchState . key . includes ( "*" ) ? searchState . key : `*${ searchState . key } *` ,
31- type : searchState . type ,
32- } ) ,
33- [ searchState ]
34- )
26+ const { search } = useDatabrowserStore ( )
3527
3628 const { fetchKeys, resetCache } = useFetchKeys ( search )
3729 const pageRef = useRef ( 0 )
You can’t perform that action at this time.
0 commit comments