Skip to content

Commit

Permalink
Se crea directorio Utils con index
Browse files Browse the repository at this point in the history
  • Loading branch information
hendaniel committed Sep 7, 2020
1 parent f256fae commit 961d2ec
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Utils/filterHelper.jsx → src/Utils/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const priceFilter = (cost) => {
export const priceFilter = (cost) => {
return (product) => {
switch (cost) {
case 1:
Expand Down
2 changes: 1 addition & 1 deletion src/components/Products/FilterPanel.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import "./products.scss";

const optionsData = {
Expand Down
17 changes: 11 additions & 6 deletions src/components/Products/ProductsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ 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;

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
);

Expand All @@ -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 (
<>
<FilterPanel
Expand All @@ -60,6 +61,10 @@ const ProductsList = () => {
</>
);
}
return <div></div>;
return (
<div className="empty">
<h1>No hay productos</h1>
</div>
);
};
export default ProductsList;
4 changes: 4 additions & 0 deletions src/components/Products/products.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@
border-radius: 100px;
height: 19px;
}
.empty {
display: flex;
justify-content: center;
}
2 changes: 1 addition & 1 deletion src/services/productsService.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as API from "../Utils/API";
import * as API from "../utils/API";

const headers = {
"Content-Type": "application/json",
Expand Down
2 changes: 1 addition & 1 deletion src/services/userService.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as API from "../Utils/API";
import * as API from "../utils/API";

const headers = {
"Content-Type": "application/json",
Expand Down

0 comments on commit 961d2ec

Please sign in to comment.