11import { IoIosSearch } from "react-icons/io" ;
2- import { useEffect , useState } from "react" ;
2+ import {
3+ // useEffect,
4+ useState } from "react" ;
35import Fuse from "fuse.js" ;
46import { updateSearchQuery } from "../../../external/bcanSatchel/actions" ;
57import { Grant } from "../../../../../middle-layer/types/Grant" ;
6- import { api } from "../../../api" ;
8+ // import { api } from "../../../api";
79import { Input } from "@chakra-ui/react" ;
810
911
10- function GrantSearch ( { onGrantSelect } : any ) {
12+ function GrantSearch ( ) {
1113 const [ userInput , setUserInput ] = useState ( "" ) ;
12- const [ grants , setGrants ] = useState < Grant [ ] > ( [ ] ) ;
13- const [ showDropdown , setShowDropdown ] = useState ( false ) ;
14- const [ dropdownGrants , setDropdownGrants ] = useState < Grant [ ] > ( [ ] ) ;
14+ // @ts -ignore
15+ const [ grants , _setGrants ] = useState < Grant [ ] > ( [ ] ) ;
16+ // const [showDropdown, setShowDropdown] = useState(false);
17+ // const [dropdownGrants, setDropdownGrants] = useState<Grant[]>([]);
1518
16- useEffect ( ( ) => {
17- fetchGrants ( ) ;
18- document . addEventListener ( "click" , handleClickOutside ) ;
19- return ( ) => {
20- document . removeEventListener ( "click" , handleClickOutside ) ;
21- } ;
22- } , [ ] ) ;
19+ // useEffect(() => {
20+ // fetchGrants();
21+ // document.addEventListener("click", handleClickOutside);
22+ // return () => {
23+ // document.removeEventListener("click", handleClickOutside);
24+ // };
25+ // }, []);
2326
24- const fetchGrants = async ( ) => {
25- try {
26- const response = await api ( `/grant` , { method : "GET" } ) ;
27- const data : Grant [ ] = await response . json ( ) ;
28- const formattedData : Grant [ ] = data . map ( ( grant : any ) => ( {
29- ...grant ,
30- organization_name : grant . organization || "Unknown Organization" ,
31- } ) ) ;
32- setGrants ( formattedData ) ;
33- } catch ( error ) {
34- console . error ( "Error fetching grants:" , error ) ;
35- }
36- } ;
27+ // const fetchGrants = async () => {
28+ // try {
29+ // const response = await api(`/grant`, { method: "GET" });
30+ // const data: Grant[] = await response.json();
31+ // const formattedData: Grant[] = data.map((grant: any) => ({
32+ // ...grant,
33+ // organization_name: grant.organization || "Unknown Organization",
34+ // }));
35+ // setGrants(formattedData);
36+ // } catch (error) {
37+ // console.error("Error fetching grants:", error);
38+ // }
39+ // };
3740
3841 const handleInputChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
3942 setUserInput ( e . target . value ) ;
@@ -42,38 +45,39 @@ function GrantSearch({ onGrantSelect }: any) {
4245
4346 const performSearch = ( query : string ) => {
4447 if ( ! query ) {
45- setDropdownGrants ( [ ] ) ;
46- setShowDropdown ( false ) ;
48+ // setDropdownGrants([]);
49+ // setShowDropdown(false);
4750 updateSearchQuery ( "" ) ;
4851 return ;
4952 }
5053 const fuse = new Fuse < Grant > ( grants , {
5154 keys : [ "organization_name" ] ,
5255 threshold : 0.3 ,
5356 } ) ;
54- const results = fuse . search ( query ) . map ( ( res ) => res . item ) ;
57+ // const results =
58+ fuse . search ( query ) . map ( ( res ) => res . item ) ;
5559 updateSearchQuery ( query ) ;
5660
57- setDropdownGrants ( results . slice ( 0 , 5 ) ) ;
58- setShowDropdown ( true ) ;
61+ // setDropdownGrants(results.slice(0, 5));
62+ // setShowDropdown(true);
5963 } ;
6064
61- const handleSelectGrant = ( selectedGrant : Grant ) => {
62- setUserInput ( selectedGrant . organization ) ;
63- updateSearchQuery ( selectedGrant . organization ) ;
64- setShowDropdown ( false ) ;
65- onGrantSelect ?.( selectedGrant ) ;
66- } ;
65+ // const handleSelectGrant = (selectedGrant: Grant) => {
66+ // setUserInput(selectedGrant.organization);
67+ // updateSearchQuery(selectedGrant.organization);
68+ // // setShowDropdown(false);
69+ // onGrantSelect?.(selectedGrant);
70+ // };
6771
68- const handleClickOutside = ( event : MouseEvent ) => {
69- const target = event . target as HTMLElement ;
70- if (
71- ! target . closest ( ".search-container" ) &&
72- ! target . closest ( ".dropdown-container" )
73- ) {
74- setShowDropdown ( false ) ;
75- }
76- } ;
72+ // const handleClickOutside = (event: MouseEvent) => {
73+ // const target = event.target as HTMLElement;
74+ // // if (
75+ // // !target.closest(".search-container") &&
76+ // // !target.closest(".dropdown-container")
77+ // // ) {
78+ // // setShowDropdown(false);
79+ // / / }
80+ // };
7781
7882 return (
7983 < div className = "search-bar-main-container" >
@@ -101,17 +105,17 @@ function GrantSearch({ onGrantSelect }: any) {
101105 className = "search-input"
102106 onChange = { handleInputChange }
103107 value = { userInput }
104- onFocus = { ( ) => setShowDropdown ( dropdownGrants . length > 0 ) }
108+ // onFocus={() => setShowDropdown(dropdownGrants.length > 0)}
105109 style = { { paddingLeft : "2rem" } } // make room for the icon
106110 onKeyDown = { ( e ) => {
107111 if ( e . key === "Enter" ) {
108112 e . preventDefault ( ) ;
109- setShowDropdown ( false ) ;
113+ // setShowDropdown(false);
110114 }
111115 } }
112116 />
113117
114- { showDropdown && (
118+ { /* { showDropdown && (
115119 <div className="dropdown-container">
116120 {dropdownGrants.length > 0 ? (
117121 dropdownGrants.map((grant, index) => (
@@ -127,7 +131,7 @@ function GrantSearch({ onGrantSelect }: any) {
127131 <div className="dropdown-item">No results found</div>
128132 )}
129133 </div>
130- ) }
134+ )} */ }
131135 </ div >
132136 </ form >
133137 </ div >
0 commit comments