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 { DefinedTool } from '@tools/defineTool'; import { filterTools, tools } from '@tools/index'; import { useNavigate } from 'react-router-dom'; import _ from 'lodash'; const exampleTools: { label: string; url: string }[] = [ { label: 'Create a transparent image', url: '/png/create-transparent' }, { label: 'Prettify JSON', url: '/json/prettify' }, { label: 'Change GIF speed', url: '/gif/change-speed' }, { label: 'Sort a list', url: '/list/sort' }, { label: 'Compress PNG', url: '/png/compress-png' }, { label: 'Split a text', url: '/string/split' }, { label: 'Calculate number sum', url: '/number/sum' }, { label: 'Shuffle a list', url: '/list/shuffle' }, { label: 'Change colors in image', url: '/png/change-colors-in-png' } ]; export default function Hero() { const [inputValue, setInputValue] = useState(''); const [filteredTools, setFilteredTools] = useState( _.shuffle(tools) ); const [pendingNavigation, setPendingNavigation] = useState(false); const navigate = useNavigate(); const handleInputChange = ( event: React.ChangeEvent<{}>, newInputValue: string ) => { setInputValue(newInputValue); setFilteredTools(_.shuffle(filterTools(tools, newInputValue))); }; useEffect(() => { if (pendingNavigation && filteredTools.length > 0) { navigate('/' + filteredTools[0].path); setPendingNavigation(false); } }, [pendingNavigation, filteredTools, navigate]); return ( Get Things Done Quickly with{' '} Omni Tools Boost your productivity with Omni Tools, the ultimate toolkit for getting things done quickly! Access thousands of user-friendly utilities for editing images, text, lists, and data, all directly from your browser. option.name} renderInput={(params) => ( , sx: { borderRadius: 4, backgroundColor: 'white' } }} onChange={(event) => handleInputChange(event, event.target.value)} /> )} renderOption={(props, option) => ( navigate('/' + option.path)} > {option.name} {option.shortDescription} )} onKeyDown={(event) => { if (event.key === 'Enter') { setPendingNavigation(true); } }} /> {exampleTools.map((tool) => ( navigate(tool.url.startsWith('/') ? tool.url : `/${tool.url}`) } item xs={12} md={6} lg={4} key={tool.label} > {tool.label} ))} ); }