Skip to content

Commit 0269068

Browse files
Merge pull request #96 from 4GeeksAcademy/alci-front
avanzando las barra de busqueda
2 parents e9fbba4 + ce9ddd1 commit 0269068

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/front/js/component/navbar.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useContext, useEffect, useState } from "react";
2-
import { Link } from "react-router-dom";
2+
import { Link, useNavigate } from "react-router-dom";
33
import { Context } from "../store/appContext";
44
import { privateUser } from "../apiservices/callToApi";
55

@@ -8,27 +8,33 @@ export const Navbar = () => {
88
const { store } = useContext(Context);
99
const [isVerified, setIsVerified] = useState(null);
1010
const [search, setSearch] = useState("");
11+
const navigate = useNavigate();
1112

12-
let products = [];
13-
const phones = store.phones;
14-
const tvs = store.tvs;
15-
const laptops = store.laptops;
16-
17-
products = phones.concat(laptops, tvs);
18-
19-
console.log(products);
20-
21-
22-
13+
const searcher = (e) => {
14+
setSearch(e.target.value)
15+
};
2316

2417
const checkout = async () =>{
2518
const verified = await privateUser()
2619
setIsVerified(verified)};
2720

21+
22+
const verifiedSearch = () => {
23+
if(search){
24+
navigate('/search-product')
25+
}else{
26+
navigate('/')
27+
};
28+
};
29+
2830
useEffect(()=>{
2931
checkout();
3032
},[]);
3133

34+
useEffect(()=>{
35+
verifiedSearch();
36+
},[search])
37+
3238
const logOut = () => {
3339
sessionStorage.removeItem('token');
3440
sessionStorage.removeItem('idUser')
@@ -47,7 +53,7 @@ export const Navbar = () => {
4753
</button>
4854
<div className="d-flex">
4955
<form className="d-flex" role="search">
50-
<input className="form-control me-2" type="search" placeholder="Search" aria-label="Search"></input>
56+
<input className="form-control me-2" onChange={(e)=>searcher(e)} type="search" placeholder="Search" aria-label="Search"></input>
5157
</form>
5258
<div className="collapse navbar-collapse" id="navbarSupportedContent">
5359
<ul className="navbar-nav me-auto mb-2 mb-lg-0">

src/front/js/layout.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Catalog } from "./pages/catalog";
1717
import { VistaIndividualTv } from "./pages/vistaIndividualTV";
1818
import { VistaIndividualLaptop } from "./pages/vistaIndividualLaptop";
1919
import { Cart } from "./pages/cart";
20+
import { SearchProduct } from "./pages/SearchProduct";
2021

2122

2223
//create your first component
@@ -45,6 +46,7 @@ const Layout = () => {
4546
<Route element={<Catalog productList="phones" />} path="/phones-catalog" />
4647
<Route element={<Catalog productList="tvs" />} path="/tvs-catalog" />
4748
<Route element={<Catalog productList="laptops" />} path="/laptops-catalog" />
49+
<Route element={<SearchProduct/>} path="/search-product" />
4850

4951
<Route element={<Cart />} path="/cart" />
5052

src/front/js/pages/SearchProduct.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useContext } from "react";
2+
import { Context } from "../store/appContext";
3+
import { CatalogProductCard } from "../component/catalog-product-card";
4+
5+
export const SearchProduct = () => {
6+
const {store} = useContext(Context);
7+
8+
let products = [];
9+
const phones = store.phones;
10+
const tvs = store.tvs;
11+
const laptops = store.laptops;
12+
13+
products = phones.concat(laptops, tvs);
14+
return (
15+
<>
16+
<h1> soy yo</h1>
17+
</>
18+
)
19+
}

0 commit comments

Comments
 (0)