diff --git a/src/views/home/home.tsx b/src/views/home/home.tsx index 4059e0de..bf14821d 100644 --- a/src/views/home/home.tsx +++ b/src/views/home/home.tsx @@ -1,6 +1,7 @@ +import { useRef } from 'react'; import styles from './home.module.css'; import useTheme from '../../hooks/use-theme'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { Trans, useTranslation } from 'react-i18next'; import { useDefaultSubplebbitAddresses } from '../../hooks/use-default-subplebbits'; import { useEffect } from 'react'; @@ -44,12 +45,45 @@ const LanguageSettings = () => { ); }; +const isValidAddress = (address: string): boolean => { + if (address.includes('/') || address.includes('\\') || address.includes(' ')) { + return false; + } + return true; +}; + const SearchBar = () => { + const searchInputRef = useRef(null); const { t } = useTranslation(); + const navigate = useNavigate(); + + const handleSearchSubmit = () => { + const inputValue = searchInputRef.current?.value; + if (inputValue && isValidAddress(inputValue)) { + navigate(`/p/${inputValue}`); + } else { + alert('invalid address'); + } + }; + return (
- - + { + if (e.key === 'Enter') { + handleSearchSubmit(); + } + }} + /> +
); };