From 961d2ec5a8b3bedac9a5a0b0d025d60dd9c180ef Mon Sep 17 00:00:00 2001 From: Daniel Martinez Date: Sun, 6 Sep 2020 23:16:13 -0500 Subject: [PATCH] Se crea directorio Utils con index --- src/Utils/{filterHelper.jsx => index.jsx} | 2 +- src/components/Products/FilterPanel.jsx | 2 +- src/components/Products/ProductsList.jsx | 17 +++++++++++------ src/components/Products/products.scss | 4 ++++ src/services/productsService.jsx | 2 +- src/services/userService.jsx | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) rename src/Utils/{filterHelper.jsx => index.jsx} (91%) diff --git a/src/Utils/filterHelper.jsx b/src/Utils/index.jsx similarity index 91% rename from src/Utils/filterHelper.jsx rename to src/Utils/index.jsx index a1596d6..19704fb 100644 --- a/src/Utils/filterHelper.jsx +++ b/src/Utils/index.jsx @@ -1,4 +1,4 @@ -const priceFilter = (cost) => { +export const priceFilter = (cost) => { return (product) => { switch (cost) { case 1: diff --git a/src/components/Products/FilterPanel.jsx b/src/components/Products/FilterPanel.jsx index 2e96975..5924262 100644 --- a/src/components/Products/FilterPanel.jsx +++ b/src/components/Products/FilterPanel.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import "./products.scss"; const optionsData = { diff --git a/src/components/Products/ProductsList.jsx b/src/components/Products/ProductsList.jsx index 8d49cea..2301457 100644 --- a/src/components/Products/ProductsList.jsx +++ b/src/components/Products/ProductsList.jsx @@ -3,6 +3,7 @@ import { usePagination } from "../../hooks/index"; import { ProductsContext } from "../../providers/index"; import Product from "./Product"; import FilterPanel from "./FilterPanel"; +import { priceFilter } from "../../utils/index"; import "./products.scss"; const ITEMS_PER_PAGE = 16; @@ -10,14 +11,14 @@ const ITEMS_PER_PAGE = 16; const ProductsList = () => { const { products, setProductResponse } = useContext(ProductsContext); - const [filter, setFilter] = useState(0); - useEffect(() => { if (!products) return; }, [products]); + const [filteredProducts, setProducts] = useState(products); + const { next, prev, currentData, currentAmount } = usePagination( - products, + filteredProducts, ITEMS_PER_PAGE ); @@ -31,10 +32,10 @@ const ProductsList = () => { }; const handleFilter = (event) => { - console.log(event.target.value); + setProducts(products.filter(priceFilter(event.target.value))); }; - if (products.length) { + if (filteredProducts.length) { return ( <> { ); } - return
; + return ( +
+

No hay productos

+
+ ); }; export default ProductsList; diff --git a/src/components/Products/products.scss b/src/components/Products/products.scss index 065af39..7ebb0c8 100644 --- a/src/components/Products/products.scss +++ b/src/components/Products/products.scss @@ -166,3 +166,7 @@ border-radius: 100px; height: 19px; } +.empty { + display: flex; + justify-content: center; +} \ No newline at end of file diff --git a/src/services/productsService.jsx b/src/services/productsService.jsx index bd06572..40d2365 100644 --- a/src/services/productsService.jsx +++ b/src/services/productsService.jsx @@ -1,4 +1,4 @@ -import * as API from "../Utils/API"; +import * as API from "../utils/API"; const headers = { "Content-Type": "application/json", diff --git a/src/services/userService.jsx b/src/services/userService.jsx index b0fd942..de116d2 100644 --- a/src/services/userService.jsx +++ b/src/services/userService.jsx @@ -1,4 +1,4 @@ -import * as API from "../Utils/API"; +import * as API from "../utils/API"; const headers = { "Content-Type": "application/json",