Skip to content

Commit

Permalink
Add debounce on claim input
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienFT committed May 16, 2024
1 parent e368d2c commit 9191111
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-import": "^2.29.1",
"husky": "^9.0.11",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tw-colors": "^3.3.1",
Expand All @@ -34,6 +35,7 @@
},
"devDependencies": {
"@types/dot-object": "^2.1.6",
"@types/lodash": "^4.17.1",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/components/InputWithRightText.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { InputMessage, InputProps } from '@massalabs/react-ui-kit';
import { debounce } from 'lodash';

export interface InputWithRightTextProps extends InputProps {
rightText: string;
}

export function InputWithRightText(props: InputWithRightTextProps) {
const { error, warning, success, disable, customClass, rightText, ...rest } =
props;
const {
error,
warning,
success,
onChange,
disable,
customClass,
rightText,
...rest
} = props;

const disabledClass = disable ? 'border-0' : '';
const errorClass = error ? 'border-s-error' : '';
Expand All @@ -15,6 +24,10 @@ export function InputWithRightText(props: InputWithRightTextProps) {
const messageClass =
errorClass || warningClass || successClass || disabledClass;

let debouncedOnChange = onChange;
if (onChange) {
debouncedOnChange = debounce(onChange, 350);
}
return (
<div className="flex-row">
<div className="grid-cols-2">
Expand All @@ -24,6 +37,7 @@ export function InputWithRightText(props: InputWithRightTextProps) {
className={`w-full default-input h-12 pl-3 pr-10 mb-1 ${messageClass} ${customClass}`}
type="text"
disabled={disable}
onChange={debouncedOnChange}
{...rest}
/>
</div>
Expand Down

0 comments on commit 9191111

Please sign in to comment.