From 49a47f54997f4d9aecfc2e9de67c183226ad49b5 Mon Sep 17 00:00:00 2001 From: Kristof Csillag Date: Fri, 7 Jul 2023 13:05:12 +0200 Subject: [PATCH] Add time delay before displaying the error and warning messages --- src/app/components/Search/index.tsx | 30 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/app/components/Search/index.tsx b/src/app/components/Search/index.tsx index cb7af29a09..b98b2b9cf4 100644 --- a/src/app/components/Search/index.tsx +++ b/src/app/components/Search/index.tsx @@ -20,7 +20,7 @@ import { SearchScope } from '../../../types/searchScope' import { textSearchMininumLength } from './search-utils' import Typography from '@mui/material/Typography' import { isValidBlockHeight } from '../../utils/helpers' -import { isValidMnemonic } from '../../utils/helpers' +// import { isValidMnemonic } from '../../utils/helpers' export type SearchVariant = 'button' | 'icon' | 'expandable' @@ -106,6 +106,7 @@ const SearchCmp: FC = ({ scope, variant, disabled, onFocusChange: o const [value, setValue] = useState('') const [isFocused, setIsFocused] = useState(false) const valueInSearchParams = useSearchParams()[0].get('q') ?? '' + const [itsTimeToAct, setItsTimeToAct] = useState(false) const wordsOfPower = t('search.wordsOfPower') const hasWordsOfPower = value.trim().toLowerCase().startsWith(wordsOfPower.toLowerCase()) @@ -163,6 +164,19 @@ const SearchCmp: FC = ({ scope, variant, disabled, onFocusChange: o : undefined const hasWarning = !!warningMessage + const hasProblem = hasError || hasWarning + + useEffect(() => { + if (hasProblem) { + const timeout = setTimeout(() => { + setItsTimeToAct(true) + }, 500) + return () => clearTimeout(timeout) + } else { + setItsTimeToAct(false) + } + }, [hasProblem]) + return ( = ({ scope, variant, disabled, onFocusChange: o > = ({ scope, variant, disabled, onFocusChange: o }} value={value} onChange={e => onChange(e.target.value)} - error={hasError || hasWarning} + error={itsTimeToAct && hasProblem} onFocus={() => onFocusChange(true)} onBlur={() => onFocusChange(false)} InputProps={{ @@ -198,11 +212,7 @@ const SearchCmp: FC = ({ scope, variant, disabled, onFocusChange: o )} - + {searchButtonContent} @@ -223,7 +233,7 @@ const SearchCmp: FC = ({ scope, variant, disabled, onFocusChange: o value && value !== valueInSearchParams && ( <> - {hasError && ( + {itsTimeToAct && hasError && ( <> = ({ scope, variant, disabled, onFocusChange: o
)} - {hasWarning && ( + {itsTimeToAct && hasWarning && ( <>