Changeset a2e5735 for frontend/src/components/Header.js
- Timestamp:
- 12/13/22 22:38:11 (23 months ago)
- Branches:
- master
- Parents:
- 113029b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/components/Header.js
r113029b ra2e5735 1 import React from "react";1 import React, { useEffect, useState } from "react"; 2 2 import logo from "../Images/logo.png"; 3 3 import "../styles/Header.css"; … … 24 24 import NavDropdown from "react-bootstrap/NavDropdown"; 25 25 import { height } from "@mui/system"; 26 import Axios from "axios"; 27 import CategoryMenu from "./CategoryMenu"; 26 28 27 29 const toggleMenu = (event) => { … … 76 78 const navigate = useNavigate(); 77 79 80 const [categories, setCategories] = useState([]); 81 //const [] 82 78 83 const signoutHandler = () => { 79 84 ctxDispatch({ type: "USER_SIGNOUT" }); … … 83 88 window.location.href = "/signin"; 84 89 }; 90 91 const searchHandler = () => { 92 let text = document.querySelector(".header__searchInput").value; 93 console.log(text); 94 navigate(`/products/search?text=${text}`); 95 }; 96 97 useEffect(() => { 98 const fetchData = async () => { 99 const cat = await Axios.get(`/api/category/getCategories`); 100 categories.splice(0, categories.length); 101 for (let i = 0; i < cat.data.length; i++) { 102 categories.push(cat.data[i]); 103 } 104 console.log(categories[0]); 105 }; 106 fetchData(); 107 }, [categories]); 108 const results = []; 109 const results1 = []; 110 const results2 = []; 111 const results3 = []; 112 if (categories) createMenu(categories); 113 function createMenu(categories) { 114 /* 115 let ul = document.getElementById("category-ul-1"); 116 for(let i=0;i<categories.length;i++){ 117 ul.appendChild() 118 }*/ 119 results.splice(0, results.length); 120 categories.forEach((category) => { 121 results.push(<CategoryMenu category={category} />); 122 }); 123 for (let i = 0; i < categories.length; i++) { 124 if (i < 3) { 125 results1.push(<CategoryMenu category={categories[i]} />); 126 } else if (i < 5) { 127 results2.push(<CategoryMenu category={categories[i]} />); 128 } else { 129 results3.push(<CategoryMenu category={categories[i]} />); 130 } 131 } 132 console.log("Results:"); 133 console.log(categories); 134 } 85 135 86 136 return ( … … 839 889 <div className="header__dropdown"> 840 890 <div className="header__dropdownColumn"> 841 <ul> 891 <ul id="category-ul-1"> 892 <li>{categories[0] && results1}</li> 893 {/* 842 894 <li> 843 895 <Link to="/products/dnevna/all"> … … 916 968 </li> 917 969 </ul> 918 </li>970 </li>*/} 919 971 </ul> 920 972 </div> 921 973 <div className="header__dropdownColumn"> 922 974 <ul> 975 <li>{categories[0] && results2}</li> 976 {/* 923 977 <li> 924 978 <Link to="/products/spalna/all"> … … 998 1052 </ul> 999 1053 </li> 1054 */} 1000 1055 </ul> 1001 1056 </div> 1002 1057 <div className="header__dropdownColumn"> 1003 1058 <ul> 1059 <li>{categories[0] && results3}</li> 1060 {/* 1004 1061 <li> 1005 1062 <Link to="/products/kancelarija/all"> … … 1083 1140 </ul> 1084 1141 </li> 1142 */} 1085 1143 </ul> 1086 1144 </div> … … 1201 1259 </div> 1202 1260 <div className="header__search"> 1203 <input className="header__searchInput" type="text" /> 1204 <SearchIcon className="header__searchIcon" fontSize="large" /> 1261 <input className="header__searchInput" type="text" name="text" /> 1262 <button onClick={searchHandler}> 1263 <SearchIcon className="header__searchIcon" fontSize="large" /> 1264 </button> 1205 1265 </div> 1206 1266 </div>
Note:
See TracChangeset
for help on using the changeset viewer.