Skip to content

Commit a03df0a

Browse files
committed
chore: handle enter press on search
1 parent d4345c3 commit a03df0a

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

.idea/workspace.xml

Lines changed: 34 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</p>
2323

2424
Welcome to OmniTools, a self-hosted web app offering a variety of online tools to simplify everyday tasks.
25-
Whether you are coding, manipulating images, crunching numbers, or OmniTools has you covered. Please don't forget to
25+
Whether you are coding, manipulating images or crunching numbers, OmniTools has you covered. Please don't forget to
2626
star the repo to support us.
2727
Here is the [demo](https://omnitools.netlify.app/) website.
2828

src/components/Hero.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Autocomplete, Box, Stack, TextField } from '@mui/material';
22
import Typography from '@mui/material/Typography';
33
import SearchIcon from '@mui/icons-material/Search';
44
import Grid from '@mui/material/Grid';
5-
import { useState } from 'react';
5+
import { useEffect, useState } from 'react';
66
import { DefinedTool } from '@tools/defineTool';
77
import { filterTools, tools } from '@tools/index';
88
import { useNavigate } from 'react-router-dom';
@@ -27,6 +27,7 @@ export default function Hero() {
2727
const [filteredTools, setFilteredTools] = useState<DefinedTool[]>(
2828
_.shuffle(tools)
2929
);
30+
const [pendingNavigation, setPendingNavigation] = useState<boolean>(false);
3031
const navigate = useNavigate();
3132
const handleInputChange = (
3233
event: React.ChangeEvent<{}>,
@@ -35,6 +36,14 @@ export default function Hero() {
3536
setInputValue(newInputValue);
3637
setFilteredTools(_.shuffle(filterTools(tools, newInputValue)));
3738
};
39+
40+
useEffect(() => {
41+
if (pendingNavigation && filteredTools.length > 0) {
42+
navigate('/' + filteredTools[0].path);
43+
setPendingNavigation(false);
44+
}
45+
}, [pendingNavigation, filteredTools, navigate]);
46+
3847
return (
3948
<Box width={{ xs: '90%', md: '80%', lg: '60%' }}>
4049
<Stack mb={1} direction={'row'} spacing={1} justifyContent={'center'}>
@@ -94,6 +103,11 @@ export default function Hero() {
94103
</Box>
95104
</Box>
96105
)}
106+
onKeyDown={(event) => {
107+
if (event.key === 'Enter') {
108+
setPendingNavigation(true);
109+
}
110+
}}
97111
/>
98112
<Grid container spacing={2} mt={2}>
99113
{exampleTools.map((tool) => (

0 commit comments

Comments
 (0)