diff --git a/src/Pages/Product.js b/src/Pages/Product.js index 45a4997..69e909a 100644 --- a/src/Pages/Product.js +++ b/src/Pages/Product.js @@ -1,145 +1,164 @@ -import React, { useState, useEffect } from 'react' -import { Link, useParams } from 'react-router-dom'; -import { useSelector, useDispatch } from 'react-redux'; -import { getProduct } from '../Redux/Actions/ProductAction'; -import ReactStars from 'react-rating-stars-component'; -import Pagination from 'react-js-pagination'; +import React, { useState, useEffect } from "react"; +import { Link, useParams } from "react-router-dom"; +import { useSelector, useDispatch } from "react-redux"; +import { getProduct } from "../Redux/Actions/ProductAction"; +import ReactStars from "react-rating-stars-component"; +import Pagination from "react-js-pagination"; import { - CategoryBody, - FilterContainer, - Img, - Item, - LoadingSection, - Map, - Name, - ProductContent, - ProductsListBody, - ProductsContainer, - RangeBody, - ReviewStar, - PaginationBody} from '../Stylesheets/Product.styled'; -import Slider from '@mui/material/Slider'; - + CategoryBody, + FilterContainer, + Img, + Item, + LoadingSection, + Map, + Name, + ProductContent, + ProductsListBody, + ProductsContainer, + RangeBody, + ReviewStar, + PaginationBody, +} from "../Stylesheets/Product.styled"; +import Slider from "@mui/material/Slider"; const Product = () => { const dispatch = useDispatch(); - - const [currentPage, setCurrentPage] = useState(1) - const [price, setPrice] = useState([1000, 50000]) - const { loading, error, products, productCount, resultPerPage, filteredProduct } = useSelector(state => state.products) - + + const [currentPage, setCurrentPage] = useState(1); + const [price, setPrice] = useState([1000, 50000]); + const { + loading, + error, + products, + productCount, + resultPerPage, + filteredProduct, + } = useSelector((state) => state.products); + // console.log('Filtered product', filteredProduct) - - const { keyword } = useParams() - + + const { keyword } = useParams(); + const setCurrentPageNo = (e) => { - setCurrentPage(e) - } - + setCurrentPage(e); + }; + const priceHandler = (event, newPrice) => { - setPrice(newPrice) - } - + setPrice(newPrice); + }; + useEffect(() => { + dispatch(getProduct(keyword, currentPage, price)); + }, [dispatch, keyword, currentPage, price]); + + const ratingChanged = () => {}; - dispatch(getProduct(keyword, currentPage, price)) - }, [dispatch, keyword, currentPage, price]) - - const ratingChanged = () => { - - } - let count = filteredProduct; - + return ( <> - - - -

Price

- - -
- - -

Category

-
-
- Stella -
-
- - {loading ? ( - <> - -
-
- - ) : ( - <> - - { - products && products?.map((product) => { - return ( - - {window.scroll(0, 0)}}> - - - - - - {window.scroll(0, 0)}}> -

{product?.name.length > 52 ? `${product?.name.substring(0, 50)}...` : product?.name}

- - -

₦{product?.price}

-

- -

-
- ({product?.numOfReviews === 0 ? ' no' : product?.numOfReviews} { - product?.numOfReviews > 1 ? 'reviews' : 'review' - }) -
-
-
- ) - }) - } - - {error && 'An error occurred. Please try again'} -
- - {resultPerPage > count && ( + + + +

Price

+ +
+ + +

Category

+
+
Stella
+
+ + {loading ? ( + <> + +
+
+ + ) : ( + <> + + {products && + products?.map((product) => { + return ( + + { + window.scroll(0, 0); + }} + > + + + + + + { + window.scroll(0, 0); + }} + > +

+ {product?.name.length > 52 + ? `${product?.name.substring(0, 50)}...` + : product?.name} +

+ + +

₦{product?.price}

+

+ +

+
+ + ( + {product?.numOfReviews === 0 + ? " no" + : product?.numOfReviews}{" "} + {product?.numOfReviews > 1 ? "reviews" : "review"} + ) + +
+
+
+ ); + })} + + {error && "An error occurred. Please try again"} +
+ + {/* {resultPerPage > count && ( */} { activeLinkClass="pageLinkActive" /> - )} - - - - )} - - - - -
+ {/* )} */} + + )} +
- ) -} + ); +}; -export default Product \ No newline at end of file +export default Product; diff --git a/src/config/index.js b/src/config/index.js index e47345f..d0195f0 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,6 +1,6 @@ const config = { - // BASE_URL: 'https://pattys-be.onrender.com' - BASE_URL: 'http://localhost:3500' + BASE_URL: "https://pattys-be.onrender.com", + // BASE_URL: 'http://localhost:3500' }; - - export default config; \ No newline at end of file + +export default config;