File tree 2 files changed +17
-11
lines changed
src/components/databrowser 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change
1
+ import { useState } from "react"
1
2
import { useDatabrowserStore } from "@/store"
2
3
import { IconX } from "@tabler/icons-react"
3
4
@@ -6,14 +7,27 @@ import { Input } from "@/components/ui/input"
6
7
7
8
export const SearchInput = ( ) => {
8
9
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
+ }
9
17
10
18
return (
11
19
< div className = "relative grow" >
12
20
< Input
13
21
placeholder = "Search"
14
22
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 }
17
31
/>
18
32
{ search . key && (
19
33
< Button
Original file line number Diff line number Diff line change @@ -23,15 +23,7 @@ const KeysContext = createContext<
23
23
export const FETCH_KEYS_QUERY_KEY = "use-fetch-keys"
24
24
25
25
export 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 ( )
35
27
36
28
const { fetchKeys, resetCache } = useFetchKeys ( search )
37
29
const pageRef = useRef ( 0 )
You can’t perform that action at this time.
0 commit comments