File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
app-catalog/src/components/charts Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import {
19
19
Typography ,
20
20
} from '@mui/material' ;
21
21
import { Autocomplete , Pagination } from '@mui/material' ;
22
- import { useEffect , useState } from 'react' ;
22
+ import { useEffect , useRef , useState } from 'react' ;
23
23
//import { jsonToYAML, yamlToJSON } from '../../helpers';
24
24
import { fetchChartsFromArtifact } from '../../api/charts' ;
25
25
//import { createRelease } from '../../api/releases';
@@ -47,6 +47,25 @@ function Search({
47
47
search,
48
48
setSearch
49
49
} : SearchProps ) {
50
+ const [ inputValue , setInputValue ] = useState ( search ) ;
51
+ const timeoutRef = useRef < NodeJS . Timeout > ( ) ;
52
+
53
+ useEffect ( ( ) => {
54
+ if ( timeoutRef . current ) {
55
+ clearTimeout ( timeoutRef . current ) ;
56
+ }
57
+
58
+ timeoutRef . current = setTimeout ( ( ) => {
59
+ setSearch ( inputValue ) ;
60
+ } , 300 ) ;
61
+
62
+ return ( ) => {
63
+ if ( timeoutRef . current ) {
64
+ clearTimeout ( timeoutRef . current ) ;
65
+ }
66
+ } ;
67
+ } , [ inputValue , setSearch ] ) ;
68
+
50
69
return (
51
70
< TextField
52
71
sx = { {
@@ -55,9 +74,9 @@ function Search({
55
74
} }
56
75
id = "outlined-basic"
57
76
label = "Search"
58
- value = { search }
77
+ value = { inputValue }
59
78
onChange = { event => {
60
- setSearch ( event . target . value ) ;
79
+ setInputValue ( event . target . value ) ;
61
80
} }
62
81
/>
63
82
) ;
You can’t perform that action at this time.
0 commit comments