Skip to content

Commit

Permalink
Se agrega navegacion y se abstrae filter panel
Browse files Browse the repository at this point in the history
  • Loading branch information
hendaniel committed Sep 7, 2020
1 parent 814877a commit 19fb60c
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 35 deletions.
11 changes: 7 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from "react";
import Banner from "./components/Banner/Banner";
import UserPanel from "./components/User/UserPanel";
import ProductsList from "./components/Products/ProductsList";
import UserProvider from "./providers/UserProvider";
import ProductsProvider from "./providers/ProductsProvider";
import HistoryProvider from "./providers/HistoryProvider";
import Navigation from "./components/User/Navigation";

function App() {
return (
<UserProvider>
<ProductsProvider>
<UserPanel />
<Banner />
<ProductsList />
<HistoryProvider>
<UserPanel />
<Banner />
<Navigation />
</HistoryProvider>
</ProductsProvider>
</UserProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import "./products.scss";
import "./filter.scss";

const optionsData = {
price: {
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/components/Products/ProductsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useContext, useState } from "react";
import { usePagination } from "../../hooks/index";
import { ProductsContext } from "../../providers/index";
import Product from "./Product";
import FilterPanel from "./FilterPanel";
import FilterPanel from "../FilterPanel/FilterPanel";
import { priceFilter } from "../../utils/index";
import "./products.scss";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useEffect, useContext, useState } from "react";
import { usePagination } from "../../hooks/index";
import { ProductsContext } from "../../providers/index";
import RedeemedProduct from "./RedeemedProduct";
import FilterPanel from "./FilterPanel";
import FilterPanel from "../FilterPanel/FilterPanel";
import { priceFilter } from "../../utils/index";
import "./products.scss";
import { HistoryContext } from "../../providers/index";
import "./history.scss";

const ITEMS_PER_PAGE = 16;

const ListHistory = () => {
const { products, setProductResponse } = useContext(ProductsContext);
const ProductsHistory = () => {
const { products } = useContext(HistoryContext);

const [filteredProducts, setProducts] = useState([]);

Expand Down Expand Up @@ -38,9 +38,7 @@ const ListHistory = () => {
/>
<div className="cards">
{currentData().map((item, key) => {
return (
<RedeemedProduct item={item} key={key} />
);
return <RedeemedProduct item={item} key={key} />;
})}
</div>
<div className="container-pagination">
Expand All @@ -60,4 +58,4 @@ const ListHistory = () => {
</div>
);
};
export default ListHistory;
export default ProductsHistory;
3 changes: 1 addition & 2 deletions src/components/ProductsHistory/RedeemedProduct.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";

import "./products.scss";
import "./history.scss";

const Product = ({
item: {
Expand Down
17 changes: 17 additions & 0 deletions src/components/User/Navigation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { Switch, Route } from "react-router-dom";
import ProductsList from "../Products/ProductsList";
import ProductsHistory from "../ProductsHistory/ProductsHistory";

const Navigation = () => {
return (
<>
<Switch>
<Route exact path="/" component={ProductsList} />
<Route exact path="/history" component={ProductsHistory} />
</Switch>
</>
);
};

export default Navigation;
45 changes: 30 additions & 15 deletions src/components/User/UserPanel.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useContext } from "react";
import { NavLink } from "react-router-dom";
import { coin } from "../../assets/index";
import { UserContext } from "../../providers/UserProvider";
import { CoinsModal } from "../Modals/index";
import { useModal } from "../../hooks/index";
import { Switch, Route } from "react-router-dom";
import ProductsList from "../Products/ProductsList";
import { routes } from "../../routes";

import "./user.scss";

const UserPanel = () => {
Expand All @@ -21,21 +22,35 @@ const UserPanel = () => {
};

const { name, points } = user;

const links = routes.map((route, key) => {
return (
<li key={key}>
<NavLink
className="nav-item"
to={route.path}
activeClassName="selected-nav"
>
{route.linkname}
</NavLink>
</li>
);
});
return (
<>
<Switch>
<Route exact path="/" component={ProductsList} />
<Route exact path="/" component={ProductsList} />

</Switch>
{coinsModal && (
<CoinsModal isShowing={coinsModal} hide={toggleCoinsModal} />
)}
<div className="user-panel">
<div>{name}</div>
<div className="coins-user">
<img src={coin} onClick={openCoinsModal} alt="Coins" />
<span className="points">{points}</span>
<div className="profile">
{coinsModal && (
<CoinsModal isShowing={coinsModal} hide={toggleCoinsModal} />
)}
<div className="navigation">
<ul className="options">{links}</ul>
</div>
<div className="user-panel">
<div>{name}</div>
<div className="coins-user">
<img src={coin} onClick={openCoinsModal} alt="Coins" />
<span className="points">{points}</span>
</div>
</div>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/providers/HistoryProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const HistoryContext = React.createContext();
const HistoryProvider = ({ children }) => {
const [products, setProducts] = useState({});

const [productResponse, setProductResponse] = useState({});
const [productResponse, setProductResponse] = useState([]);

useEffect(() => {
getHistory().then((products) => {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ProductsProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const ProductsContext = React.createContext();
const ProductsProvider = ({ children }) => {
const [products, setProducts] = useState({});

const [productResponse, setProductResponse] = useState({});
const [productResponse, setProductResponse] = useState([]);

useEffect(() => {
getProducts().then((products) => {
Expand Down
3 changes: 2 additions & 1 deletion src/providers/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ProductsContext } from "./ProductsProvider";
import { UserContext } from "./UserProvider";
import { HistoryContext } from "./HistoryProvider";

export { ProductsContext, UserContext };
export { ProductsContext, UserContext, HistoryContext };

0 comments on commit 19fb60c

Please sign in to comment.