From 44f65b2fcc7f6b7ae00cfd3ef0b1c688461ab5c4 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Tue, 31 Dec 2024 10:57:42 +0100 Subject: [PATCH] refactor: extract utility --- apps/client/src/common/utils/keyEvent.ts | 8 ++++++++ .../panel/integrations-panel/OscIntegrations.tsx | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/client/src/common/utils/keyEvent.ts b/apps/client/src/common/utils/keyEvent.ts index 30bf3c6e1..aa8e18e94 100644 --- a/apps/client/src/common/utils/keyEvent.ts +++ b/apps/client/src/common/utils/keyEvent.ts @@ -7,3 +7,11 @@ export function isKeyEnter(event: KeyboardEvent): boolean { export function isKeyEscape(event: KeyboardEvent): boolean { return event.key === 'Escape'; } + +export function preventEscape(event: KeyboardEvent, callback?: () => void): void { + if (isKeyEscape(event)) { + event.preventDefault(); + event.stopPropagation(); + callback?.(); + } +} diff --git a/apps/client/src/features/app-settings/panel/integrations-panel/OscIntegrations.tsx b/apps/client/src/features/app-settings/panel/integrations-panel/OscIntegrations.tsx index d124a2313..b23583685 100644 --- a/apps/client/src/features/app-settings/panel/integrations-panel/OscIntegrations.tsx +++ b/apps/client/src/features/app-settings/panel/integrations-panel/OscIntegrations.tsx @@ -8,7 +8,7 @@ import { generateId } from 'ontime-utils'; import { maybeAxiosError } from '../../../../common/api/utils'; import useOscSettings, { useOscSettingsMutation } from '../../../../common/hooks-query/useOscSettings'; -import { isKeyEscape } from '../../../../common/utils/keyEvent'; +import { preventEscape } from '../../../../common/utils/keyEvent'; import { isASCII, isASCIIorEmpty, isIPAddress, isOnlyNumbers, startsWithSlash } from '../../../../common/utils/regex'; import { isOntimeCloud } from '../../../../externals'; import * as Panel from '../../panel-utils/PanelUtils'; @@ -63,13 +63,6 @@ export default function OscIntegrations() { } }; - const preventEscape = (event: React.KeyboardEvent) => { - if (isKeyEscape(event)) { - event.preventDefault(); - event.stopPropagation(); - } - }; - const handleAddNewSubscription = () => { prepend({ id: generateId(),