Changeset 3e98cea for reactapp/src/Components/Search.js
- Timestamp:
- 08/06/22 18:16:44 (2 years ago)
- Branches:
- main
- Children:
- 800779d
- Parents:
- d654c74
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Components/Search.js
rd654c74 r3e98cea 3 3 import { transliterate } from "../Util/transliterate"; 4 4 import { 5 SearchDropdownResultSmall, 6 SearchDropdownTextSmall, 7 SearchDropdownSmall, 8 SearchDropdownResultLinkSmall, 9 SearchSmall, 10 } from "./Search.style"; 5 SearchResult, 6 SearchResultText, 7 SearchDropdown, 8 SearchResultLink, 9 SearchBox, 10 } from "./Styled/Search.style"; 11 import { useNavigate } from "react-router"; 11 12 function Search() { 12 13 const [query, setQuery] = useState(""); … … 27 28 //setLoaded(true); 28 29 } catch (error) { 29 console.log(" Error", error);30 console.log("Fetching error occured", error); 30 31 } 31 32 }; … … 33 34 if (query.length > 2) fetchData(); 34 35 }, [query]); 36 37 const navigate = useNavigate(); 38 39 const handleKeyDown = (event) => { 40 if (event.key === "Enter") { 41 setExpanded(false); 42 navigate("/search", { state: professors }); 43 } 44 }; 45 46 const [expanded, setExpanded] = useState(false); 47 48 function expand() { 49 setExpanded(true); 50 } 51 52 function close() { 53 setExpanded(false); 54 } 35 55 36 56 return ( … … 42 62 }} 43 63 > 44 <Search Small64 <SearchBox 45 65 placeholder="Пребарувај..." 46 66 onChange={(e) => setQuery(e.target.value)} 67 onKeyDown={handleKeyDown} 68 tabIndex={0} 69 onFocus={expand} 70 onBlur={close} 47 71 /> 48 <SearchDropdownSmall 49 display={query.length > 2 && professors.length > 0 ? "block" : "none"} 72 <SearchDropdown 73 display={ 74 query.length > 2 && professors.length > 0 && expanded 75 ? "block" 76 : "none" 77 } 50 78 > 51 79 {query.length > 2 && 52 80 professors.slice(0, 7).map((professor) => ( 53 <SearchDropdownResultSmall key={professor.professorId}> 54 <SearchDropdownResultLinkSmall 55 href={"/professor/" + professor.professorId} 56 > 57 <SearchDropdownTextSmall weight="bold" size="medium"> 81 <SearchResult 82 key={professor.professorId} 83 onMouseDown={(event) => { 84 event.preventDefault(); 85 event.stopPropagation(); 86 }} 87 margin="0" 88 > 89 <SearchResultLink href={"/professor/" + professor.professorId}> 90 <SearchResultText weight="bold" size="medium"> 58 91 {professor.professorName} 59 </Search DropdownTextSmall>60 <Search DropdownTextSmall weight="normal" size="smaller">92 </SearchResultText> 93 <SearchResultText weight="normal" size="er"> 61 94 {professor.faculty.facultyName} 62 </Search DropdownTextSmall>63 </Search DropdownResultLinkSmall>64 </Search DropdownResultSmall>95 </SearchResultText> 96 </SearchResultLink> 97 </SearchResult> 65 98 ))} 66 </SearchDropdown Small>99 </SearchDropdown> 67 100 </div> 68 101 );
Note:
See TracChangeset
for help on using the changeset viewer.