From a47bf8b800f8ba9305ae84d285f0bcacc9e20e03 Mon Sep 17 00:00:00 2001 From: "Ibrahima G. Coulibaly" Date: Thu, 6 Mar 2025 17:54:36 +0000 Subject: [PATCH] fix: search bar --- src/components/Hero.tsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/Hero.tsx b/src/components/Hero.tsx index 59fbd13..d5ff305 100644 --- a/src/components/Hero.tsx +++ b/src/components/Hero.tsx @@ -2,7 +2,7 @@ import { Autocomplete, Box, Stack, TextField } from '@mui/material'; import Typography from '@mui/material/Typography'; import SearchIcon from '@mui/icons-material/Search'; import Grid from '@mui/material/Grid'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { DefinedTool } from '@tools/defineTool'; import { filterTools, tools } from '@tools/index'; import { useNavigate } from 'react-router-dom'; @@ -28,7 +28,6 @@ export default function Hero() { const [filteredTools, setFilteredTools] = useState( _.shuffle(tools) ); - const [pendingNavigation, setPendingNavigation] = useState(false); const navigate = useNavigate(); const handleInputChange = ( event: React.ChangeEvent<{}>, @@ -38,13 +37,6 @@ export default function Hero() { setFilteredTools(_.shuffle(filterTools(tools, newInputValue))); }; - useEffect(() => { - if (pendingNavigation && filteredTools.length > 0) { - navigate('/' + filteredTools[0].path); - setPendingNavigation(false); - } - }, [pendingNavigation, filteredTools, navigate]); - return ( @@ -107,9 +99,9 @@ export default function Hero() { )} - onKeyDown={(event) => { - if (event.key === 'Enter') { - setPendingNavigation(true); + onChange={(event, newValue) => { + if (newValue) { + navigate('/' + newValue.path); } }} />