Changeset a2e5735 for frontend/src/screens/CategoryScreen.js
- Timestamp:
- 12/13/22 22:38:11 (19 months ago)
- Branches:
- master
- Parents:
- 113029b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/screens/CategoryScreen.js
r113029b ra2e5735 1 import React, { useEffect, useReducer } from "react";1 import React, { useEffect, useReducer, useState } from "react"; 2 2 import "../styles/Home.css"; 3 3 // import data from "./data"; … … 34 34 const params = useParams(); 35 35 const { category, subCategory } = params; 36 var HF = 0; 37 var HT = 1000; 38 var WF = 0; 39 var WT = 1000; 40 var LF = 0; 41 var LT = 1000; 42 //const [HT, setHT] = useState(1000); 43 //const [WF, setWF] = useState(0); 44 //const [WT, setWT] = useState(1000); 45 //const [LF, setLF] = useState(0); 46 //const [LT, setLT] = useState(1000); 36 47 const navigate = useNavigate(); 37 48 const { search } = useLocation(); … … 43 54 const order = sp.get("order") || "newest"; 44 55 const page = sp.get("page") || 1; 45 46 56 const [{ loading, error, products, pages, countProducts }, dispatch] = 47 57 useReducer(reducer, { loading: true, error: "" }); … … 56 66 );*/ 57 67 const { data } = await axios.get( 58 `/api/products?page=${page}&query=${query}&category=${category}&subCategory=${subCategory}&order=${order} `68 `/api/products?page=${page}&query=${query}&category=${category}&subCategory=${subCategory}&order=${order}&HF=${HF}&HT=${HT}&WF=${WF}&WT=${WT}&LF=${LF}<=${LT}` 59 69 ); 60 70 dispatch({ type: "FETCH_SUCCESS", payload: data }); … … 64 74 }; 65 75 fetchData(); 66 }, [category, page, query, order, subCategory, error]); 76 }, [ 77 category, 78 page, 79 query, 80 order, 81 subCategory, 82 error, 83 HF, 84 HT, 85 WF, 86 WT, 87 LF, 88 LT, 89 ]); 67 90 68 91 const getFilterUrl = (filter) => { … … 72 95 const filterSubCategory = filter.subCategory || subCategory; 73 96 const sortOrder = filter.order || order; 74 return `?category=${filterCategorry}&query=${filterQuery}&subCategory=${filterSubCategory}&page=${filterPage}&order=${sortOrder}`; 97 const filterHF = filter.HF || HF; 98 const filterHT = filter.HT || HT; 99 const filterWF = filter.WF || WF; 100 const filterWT = filter.WT || WT; 101 const filterLF = filter.LF || LF; 102 const filterLT = filter.LT || LT; 103 return `?category=${filterCategorry}&query=${filterQuery}&subCategory=${filterSubCategory}&page=${filterPage}&order=${sortOrder}&HF=${filterHF}&HT=${filterHT}&WF=${filterWF}&WT=${filterWT}&LF=${filterLF}<=${filterLT}`; 104 }; 105 106 const filterHandler = (e) => { 107 e.preventDefault(); 108 HF = document.getElementById("HF").value; 109 HT = document.getElementById("HT").value; 110 WF = document.getElementById("WF").value; 111 WT = document.getElementById("WT").value; 112 LF = document.getElementById("LF").value; 113 LT = document.getElementById("LT").value; 114 console.log(HT); 115 const fetchData = async () => { 116 try { 117 dispatch({ type: "FETCH_REQUEST" }); 118 /* 119 const { data } = await axios.get( 120 `/api/products/search?page=${page}&query=${query}&category=${category}&subCategory=${subCategory}&order=${order}` 121 );*/ 122 const { data } = await axios.get( 123 `/api/products?page=${page}&query=${query}&category=${category}&subCategory=${subCategory}&order=${order}&HF=${HF}&HT=${HT}&WF=${WF}&WT=${WT}&LF=${LF}<=${LT}` 124 ); 125 dispatch({ type: "FETCH_SUCCESS", payload: data }); 126 } catch (err) { 127 dispatch({ type: "FETCH_FAIL", payload: getError(err) }); 128 } 129 }; 130 fetchData(); 75 131 }; 76 132 … … 124 180 > 125 181 <Form 182 onSubmit={filterHandler} 126 183 style={{ 127 184 width: "100%", 128 185 display: "flex", 129 justifyContent: " end",186 justifyContent: "space-around", 130 187 marginRight: "40px", 131 188 alignItems: "center", 132 189 }} 133 190 > 191 <Form.Group style={{ display: "flex", alignItems: "center" }}> 192 <Form.Label style={{ margin: "0px" }}>H:</Form.Label> 193 <Form.Control 194 style={{ width: "60px" }} 195 id="HF" 196 //onChange={(e) => setHF(e.target.value)} 197 /> 198 <Form.Label style={{ margin: "0px" }}>-</Form.Label> 199 <Form.Control 200 style={{ width: "60px" }} 201 id="HT" 202 //onChange={(e) => setHT(e.target.value)} 203 /> 204 </Form.Group> 205 <Form.Group style={{ display: "flex", alignItems: "center" }}> 206 <Form.Label style={{ margin: "0px" }}>W:</Form.Label> 207 <Form.Control 208 style={{ width: "60px" }} 209 id="WF" 210 //onChange={(e) => setWF(e.target.value)} 211 /> 212 <Form.Label style={{ margin: "0px" }}>-</Form.Label> 213 <Form.Control 214 style={{ width: "60px" }} 215 id="WT" 216 //onChange={(e) => setWT(e.target.value)} 217 /> 218 </Form.Group> 219 <Form.Group style={{ display: "flex", alignItems: "center" }}> 220 <Form.Label style={{ margin: "0px" }}>L:</Form.Label> 221 <Form.Control 222 id="LF" 223 style={{ width: "60px" }} 224 //onChange={(e) => setLF(e.target.value)} 225 /> 226 <Form.Label style={{ margin: "0px" }}>-</Form.Label> 227 <Form.Control 228 id="LT" 229 style={{ width: "60px" }} 230 //onChange={(e) => setLT(e.target.value)} 231 /> 232 </Form.Group> 134 233 {/*} 135 234 <Form.Group> … … 292 391 <option value={"highFirst"}>Од висока кон ниска</option> 293 392 </Form.Select> 393 </Form.Group> 394 <Form.Group> 395 <Button variant="danger" size="lg" type="submit"> 396 Филтрирај 397 </Button> 294 398 </Form.Group> 295 399 </Form>
Note:
See TracChangeset
for help on using the changeset viewer.