From a63c8731422db62d3a91e5e58f1b2fd49b63ca49 Mon Sep 17 00:00:00 2001 From: Jack Kavanagh Date: Fri, 8 Jul 2022 13:40:40 +0200 Subject: [PATCH] transform (#4936) --- .../ui/components/sidebar/sidebar-filter.tsx | 101 +++++++----------- 1 file changed, 39 insertions(+), 62 deletions(-) diff --git a/packages/insomnia/src/ui/components/sidebar/sidebar-filter.tsx b/packages/insomnia/src/ui/components/sidebar/sidebar-filter.tsx index 7025376189..53b0a6676e 100644 --- a/packages/insomnia/src/ui/components/sidebar/sidebar-filter.tsx +++ b/packages/insomnia/src/ui/components/sidebar/sidebar-filter.tsx @@ -1,8 +1,7 @@ -import { autoBindMethodsForReact } from 'class-autobind-decorator'; import { HotKeyRegistry } from 'insomnia-common'; -import React, { PureComponent } from 'react'; +import React, { FC, useCallback, useRef } from 'react'; -import { AUTOBIND_CFG, DEBOUNCE_MILLIS, SortOrder } from '../../../common/constants'; +import { SortOrder } from '../../../common/constants'; import { hotKeyRefs } from '../../../common/hotkeys'; import { executeHotKey } from '../../../common/hotkeys-listener'; import { KeydownBinder } from '../keydown-binder'; @@ -15,67 +14,45 @@ interface Props { filter: string; hotKeyRegistry: HotKeyRegistry; } - -@autoBindMethodsForReact(AUTOBIND_CFG) -export class SidebarFilter extends PureComponent { - _input: HTMLInputElement | null = null; - _triggerTimeout: NodeJS.Timeout | null = null; - - _setInputRef(input: HTMLInputElement) { - this._input = input; - } - - _handleClearFilter() { - this.props.onChange(''); - - if (this._input) { - this._input.value = ''; - - this._input.focus(); +export const SidebarFilter: FC = ({ filter, hotKeyRegistry, sidebarSort, onChange }) => { + const inputRef = useRef(null); + const handleClearFilter = useCallback(() => { + onChange(''); + if (inputRef.current) { + inputRef.current.value = ''; + inputRef.current.focus(); } - } - - _handleOnChange(event: React.SyntheticEvent) { - const value = event.currentTarget.value; - if (this._triggerTimeout) { - clearTimeout(this._triggerTimeout); - } - this._triggerTimeout = setTimeout(() => { - this.props.onChange(value); - }, DEBOUNCE_MILLIS); - } - - _handleKeydown(event: KeyboardEvent) { + }, [onChange]); + const handleOnChange = useCallback((event: React.SyntheticEvent) => { + onChange(event.currentTarget.value); + }, [onChange]); + const handleKeydown = useCallback((event: KeyboardEvent) => { executeHotKey(event, hotKeyRefs.SIDEBAR_FOCUS_FILTER, () => { - this._input?.focus(); + inputRef.current?.focus(); }); - } - - render() { - const { filter, hotKeyRegistry, sidebarSort } = this.props; - return ( - -
-
- - {filter && ( - - )} -
- - +
+
+ + {filter && ( + + )}
- - ); - } -} + + +
+ + ); +};