From 2f76cb0c6df5d1f7cebe627532eb8cb43b112cfe Mon Sep 17 00:00:00 2001 From: Jack Kavanagh Date: Fri, 21 Oct 2022 16:01:50 +0100 Subject: [PATCH] Remove/debounced-input (#5308) * first pass * remove debounced input * fix onPaste type errors --- .../ui/components/base/debounced-input.tsx | 171 ------------------ .../ui/components/codemirror/code-editor.tsx | 6 +- .../components/codemirror/one-line-editor.tsx | 51 +++--- .../graph-ql-explorer/graph-ql-explorer.tsx | 17 +- .../ui/components/key-value-editor/row.tsx | 8 +- .../modals/project-settings-modal.tsx | 7 +- .../modals/request-group-settings-modal.tsx | 9 +- .../modals/request-settings-modal.tsx | 9 +- .../modals/workspace-settings-modal.tsx | 7 +- 9 files changed, 49 insertions(+), 236 deletions(-) delete mode 100644 packages/insomnia/src/ui/components/base/debounced-input.tsx diff --git a/packages/insomnia/src/ui/components/base/debounced-input.tsx b/packages/insomnia/src/ui/components/base/debounced-input.tsx deleted file mode 100644 index af00c71716..0000000000 --- a/packages/insomnia/src/ui/components/base/debounced-input.tsx +++ /dev/null @@ -1,171 +0,0 @@ -import { autoBindMethodsForReact } from 'class-autobind-decorator'; -import React, { PureComponent } from 'react'; - -import { AUTOBIND_CFG } from '../../../common/constants'; -import { debounce } from '../../../common/misc'; - -interface Props { - onChange: (value: string) => void; - onFocus?: (event: React.FocusEvent) => void; - onBlur?: (event: React.FocusEvent) => void; - textarea?: boolean; - delay?: number; - placeholder?: string; - initialValue?: string; -} - -@autoBindMethodsForReact(AUTOBIND_CFG) -export class DebouncedInput extends PureComponent { - _hasFocus = false; - _input: HTMLTextAreaElement | HTMLInputElement | null = null; - _handleValueChange: Props['onChange'] | null = null; - - constructor(props: Props) { - super(props); - - if (!props.delay) { - this._handleValueChange = props.onChange; - } else { - this._handleValueChange = debounce(props.onChange, props.delay || 500); - } - } - - componentDidMount() { - if (this._input && this.props.initialValue) { - this._input.value = this.props.initialValue; - } - } - - _handleChange(event: React.ChangeEvent) { - this._handleValueChange?.(event.target.value); - } - - _handleFocus(event: React.FocusEvent) { - this._hasFocus = true; - this.props.onFocus?.(event); - } - - _handleBlur(event: React.FocusEvent) { - this._hasFocus = false; - this.props.onBlur?.(event); - } - - _setRef(input: HTMLTextAreaElement | HTMLInputElement) { - this._input = input; - } - - setAttribute(name: string, value: string) { - this._input?.setAttribute(name, value); - } - - removeAttribute(name: string) { - this._input?.removeAttribute(name); - } - - getAttribute(name: string) { - this._input?.getAttribute(name); - } - - hasFocus() { - return this._hasFocus; - } - - getSelectionStart() { - if (this._input) { - return this._input.selectionStart; - } else { - return -1; - } - } - - getSelectionEnd() { - if (this._input) { - return this._input.selectionEnd; - } else { - return -1; - } - } - - focus() { - if (this._input) { - this._input.focus(); - } - } - - focusEnd() { - if (this._input) { - // Hack to focus the end (set value to current value); - this._input.value = this.getValue(); - - this._input.focus(); - } - } - - blur() { - if (this._input) { - this._input.blur(); - } - } - - select() { - if (this._input) { - this._input.select(); - } - } - - getValue() { - if (this._input) { - return this._input.value; - } else { - return ''; - } - } - - setValue(value: string) { - if (this._input) { - this._input.value = value; - } - } - - render() { - const { - onChange, - // eslint-disable-line @typescript-eslint/no-unused-vars - onFocus, - // eslint-disable-line @typescript-eslint/no-unused-vars - onBlur, - // eslint-disable-line @typescript-eslint/no-unused-vars - delay, - // eslint-disable-line @typescript-eslint/no-unused-vars - textarea, - initialValue, - ...props - } = this.props; - - if (textarea) { - return ( -