147 lines
4.7 KiB
TypeScript
Raw Normal View History

2024-06-25 09:35:44 +01:00
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';
2025-02-27 00:09:15 +00:00
import { useEffect, useState } from 'react';
2024-06-25 09:35:44 +01:00
import { DefinedTool } from '@tools/defineTool';
import { filterTools, tools } from '@tools/index';
import { useNavigate } from 'react-router-dom';
2024-06-26 02:00:54 +01:00
import _ from 'lodash';
2024-06-25 09:35:44 +01:00
const exampleTools: { label: string; url: string }[] = [
{
label: 'Create a transparent image',
url: '/png/create-transparent'
},
{ label: 'Convert text to morse code', url: '/string/to-morse' },
2024-06-27 12:39:38 +01:00
{ label: 'Change GIF speed', url: '/gif/change-speed' },
2025-02-25 13:02:00 +00:00
{ label: 'Sort a list', url: '/list/sort' },
{ label: 'Compress PNG', url: '/png/compress-png' },
2025-02-23 01:38:42 +01:00
{ label: 'Split a text', url: '/string/split' },
2024-06-25 09:35:44 +01:00
{ label: 'Calculate number sum', url: '/number/sum' },
2025-02-25 13:02:00 +00:00
{ label: 'Shuffle a list', url: '/list/shuffle' },
{ label: 'Change colors in image', url: '/png/change-colors-in-png' }
2024-06-25 09:35:44 +01:00
];
export default function Hero() {
const [inputValue, setInputValue] = useState<string>('');
2024-06-26 02:00:54 +01:00
const [filteredTools, setFilteredTools] = useState<DefinedTool[]>(
_.shuffle(tools)
);
2025-02-27 00:09:15 +00:00
const [pendingNavigation, setPendingNavigation] = useState<boolean>(false);
2024-06-25 09:35:44 +01:00
const navigate = useNavigate();
const handleInputChange = (
event: React.ChangeEvent<{}>,
newInputValue: string
) => {
setInputValue(newInputValue);
2024-06-26 02:00:54 +01:00
setFilteredTools(_.shuffle(filterTools(tools, newInputValue)));
2024-06-25 09:35:44 +01:00
};
2025-02-27 00:09:15 +00:00
useEffect(() => {
if (pendingNavigation && filteredTools.length > 0) {
navigate('/' + filteredTools[0].path);
setPendingNavigation(false);
}
}, [pendingNavigation, filteredTools, navigate]);
2024-06-25 09:35:44 +01:00
return (
2024-06-26 00:29:53 +01:00
<Box width={{ xs: '90%', md: '80%', lg: '60%' }}>
<Stack mb={1} direction={'row'} spacing={1} justifyContent={'center'}>
<Typography sx={{ textAlign: 'center' }} fontSize={{ xs: 25, md: 30 }}>
2025-02-23 00:41:04 +01:00
Get Things Done Quickly with{' '}
2024-06-26 00:29:53 +01:00
<Typography
fontSize={{ xs: 25, md: 30 }}
display={'inline'}
color={'primary'}
>
Omni Tools
</Typography>
2024-06-25 09:35:44 +01:00
</Typography>
</Stack>
2024-06-26 00:29:53 +01:00
<Typography
sx={{ textAlign: 'center' }}
fontSize={{ xs: 15, md: 20 }}
mb={2}
>
2024-06-25 09:35:44 +01:00
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.
</Typography>
<Autocomplete
sx={{ mb: 2 }}
autoHighlight
options={filteredTools}
2024-06-26 02:00:54 +01:00
inputValue={inputValue}
2024-06-25 09:35:44 +01:00
getOptionLabel={(option) => option.name}
renderInput={(params) => (
<TextField
{...params}
fullWidth
placeholder={'Search all tools'}
InputProps={{
...params.InputProps,
2025-02-23 14:11:21 +00:00
endAdornment: <SearchIcon />,
sx: {
2025-02-25 06:17:10 +00:00
borderRadius: 4,
backgroundColor: 'white'
2025-02-23 14:11:21 +00:00
}
2024-06-25 09:35:44 +01:00
}}
onChange={(event) => handleInputChange(event, event.target.value)}
/>
)}
renderOption={(props, option) => (
2024-06-27 20:27:03 +01:00
<Box
component="li"
{...props}
onClick={() => navigate('/' + option.path)}
>
2024-06-25 09:35:44 +01:00
<Box>
<Typography fontWeight={'bold'}>{option.name}</Typography>
<Typography fontSize={12}>{option.shortDescription}</Typography>
</Box>
</Box>
)}
2025-02-27 00:09:15 +00:00
onKeyDown={(event) => {
if (event.key === 'Enter') {
setPendingNavigation(true);
}
}}
2024-06-25 09:35:44 +01:00
/>
<Grid container spacing={2} mt={2}>
{exampleTools.map((tool) => (
2024-06-26 00:29:53 +01:00
<Grid
2025-02-25 13:02:00 +00:00
onClick={() =>
navigate(tool.url.startsWith('/') ? tool.url : `/${tool.url}`)
}
2024-06-26 00:29:53 +01:00
item
xs={12}
md={6}
lg={4}
key={tool.label}
>
2024-06-25 09:35:44 +01:00
<Box
sx={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderWidth: 1,
padding: 1,
borderRadius: 3,
borderColor: 'grey',
borderStyle: 'solid',
2025-02-25 06:17:10 +00:00
backgroundColor: 'white',
2025-02-23 14:11:21 +00:00
cursor: 'pointer',
'&:hover': { backgroundColor: '#FAFAFD' }
2024-06-25 09:35:44 +01:00
}}
>
<Typography>{tool.label}</Typography>
</Box>
</Grid>
))}
</Grid>
</Box>
);
}