Skip to content

Commit

Permalink
refactor: extract utility
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Dec 31, 2024
1 parent 760de60 commit 44f65b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 8 additions & 0 deletions apps/client/src/common/utils/keyEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ export function isKeyEnter<T>(event: KeyboardEvent<T>): boolean {
export function isKeyEscape<T>(event: KeyboardEvent<T>): boolean {
return event.key === 'Escape';
}

export function preventEscape<T>(event: KeyboardEvent<T>, callback?: () => void): void {
if (isKeyEscape(event)) {
event.preventDefault();
event.stopPropagation();
callback?.();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 44f65b2

Please sign in to comment.