-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#21): implement search in tree list page
- Loading branch information
Showing
4 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import { ChangeEvent, useCallback, useState } from "react"; | ||
|
||
import SideMenu from "../SideMenu/SideMenu"; | ||
import TopBar from "../TopBar/TopBar"; | ||
import TreeListingPage from "../TreeListingPage/TreeListingPage"; | ||
import { useDebounce } from "../../hooks/useDebounce"; | ||
|
||
const Dashboard = () : JSX.Element => { | ||
const [inputSearchText, setInputSearchText] = useState(''); | ||
const debouncedInput = useDebounce(inputSearchText, DEBOUNCE_INTERVAL); | ||
|
||
const onInputSearchTextChange = useCallback((e: ChangeEvent<HTMLInputElement>) => { | ||
setInputSearchText(e.target.value); | ||
}, []); | ||
|
||
return ( | ||
<div className="w-full h-full"> | ||
<div className="flex flex-row w-full justify-between"> | ||
<SideMenu /> | ||
<TopBar /> | ||
<TopBar onChangeInputText={onInputSearchTextChange}/> | ||
<div className="w-full px-16 pt-24 bg-lightGray"> | ||
<TreeListingPage /> | ||
<TreeListingPage inputFilter={debouncedInput}/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const DEBOUNCE_INTERVAL = 300; | ||
|
||
export default Dashboard; |
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,16 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
export const useDebounce = (input: string, delay: number): string => { | ||
const [debouncedValue, setDebouncedValue] = useState(input); | ||
|
||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedValue(input); | ||
}, delay); | ||
return (): void => { | ||
clearTimeout(handler); | ||
}; | ||
}, [input, delay]); | ||
|
||
return debouncedValue; | ||
}; |