diff --git a/src/front/components/Navbar.css b/src/front/components/Navbar.css index e69de29bb2..e96bf27585 100644 --- a/src/front/components/Navbar.css +++ b/src/front/components/Navbar.css @@ -0,0 +1,29 @@ +.searchBar { + position: relative; + & .bar { + display: flex; + width: 20rem; + height: 2rem; + & .inputhori { + background: transparent; + width: 100%; + margin-right: 1rem; + } + } + & .results { + display: flex; + flex-direction: column; + position: absolute; + top: 2.5rem; + right: 0; + width: 20rem; + z-index: 1000; + border: 1px solid rgb(73, 73, 73); + border-radius: 5px; + padding: 10px; + gap: 5px; + & span { + color: white; + } + } +} \ No newline at end of file diff --git a/src/front/components/Navbar.jsx b/src/front/components/Navbar.jsx index 67feeb5de5..eab6a395a7 100644 --- a/src/front/components/Navbar.jsx +++ b/src/front/components/Navbar.jsx @@ -9,12 +9,13 @@ import useGlobalReducer from "../hooks/useGlobalReducer"; export default function Navbar({ showDrowpdown, setShowDrowpdown }) { const { store, dispatch } = useGlobalReducer() const { all_games } = store; - console.log(all_games) const navigate = useNavigate() const token_user = localStorage.getItem('jwt-token'); const user = localStorage.getItem('user'); const [view, setview] = useState(false); const [searchGame, setSearchGame] = useState() /* Barra de buscar funcional*/ + const [gamesFilter, setGamesFilter] = useState([]) /* Barra de buscar funcional*/ + const handleSearch = () => { @@ -45,22 +46,28 @@ export default function Navbar({ showDrowpdown, setShowDrowpdown }) { } else { setview(false) } - console.log("hola", user, "Asdasd") }, [token_user]); const search = () => { - const game = all_games.find(game => game.name === searchGame) - console.log(game) - console.log(game.id) - navigate(`/DetailsGames/${game.id}`) - - if (!game.name == searchGame) + if (!game) { alert("Juego no encontrado") + } else { + navigate(`/DetailsGames/${game.id}`) + } + } + const filter = (text) => { + let filterGames = all_games.filter((g) => { + return g.name.toLowerCase().includes(text.toLowerCase()) + }) + setGamesFilter(filterGames) } + console.log(gamesFilter) + + return (