-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch improves search with help of debounce and adds searched input to url as `search_query` Signed-off-by: Shiv Verma <shverma@redhat.com>
- Loading branch information
1 parent
1e88cc8
commit 6ac010e
Showing
11 changed files
with
28,250 additions
and
3,295 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { FakeHub } from '../api/testutil'; | ||
import { createProviderAndStore } from '../store/root'; | ||
import { useDebounce } from './useDebounce'; | ||
|
||
const TESTDATA_DIR = `src/store/testdata`; | ||
const api = new FakeHub(TESTDATA_DIR); | ||
const {} = createProviderAndStore(api); | ||
|
||
describe('useDebounce', () => { | ||
it('it renders useDebounce', (done) => { | ||
const { result } = renderHook(() => useDebounce('cli', 400)); | ||
expect(result.current).toBe('cli'); | ||
|
||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useMst } from '../store/root'; | ||
|
||
export const useDebounce = (value: string, delay: number) => { | ||
const [debouncedValue, setDebouncedValue] = useState(value); | ||
const { resources } = useMst(); | ||
|
||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedValue(value); | ||
resources.setSearch(value); | ||
}, delay); | ||
|
||
return () => { | ||
clearTimeout(handler); | ||
}; | ||
}, [value, delay, resources]); | ||
return debouncedValue; | ||
}; |