Skip to content

Commit b1aafd2

Browse files
committed
refactor: remove ts-key-enum dependency and replace its usage with string literals in keyboard event handling
1 parent 856e2d1 commit b1aafd2

File tree

9 files changed

+19
-30
lines changed

9 files changed

+19
-30
lines changed

bun.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"prettier": "^3.5.1",
7878
"prettier-plugin-tailwindcss": "^0.7.0",
7979
"tailwindcss": "^4.1.14",
80-
"ts-key-enum": "^2.0.12",
8180
"typescript": "^5.1.6",
8281
"typescript-plugin-css-modules": "^5.0.1"
8382
},

packages/web/src/views/Day/components/Agenda/Agenda.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import classNames from "classnames";
22
import { useCallback, useEffect, useRef, useState } from "react";
33
import { BehaviorSubject, distinctUntilChanged } from "rxjs";
4-
import { Key } from "ts-key-enum";
54
import { distinctUntilArrayItemChanged } from "@ngneat/elf";
65
import {
76
UIEntitiesRef,

packages/web/src/views/Day/components/Agenda/Events/AllDayAgendaEvent/AllDayAgendaEvents.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import classNames from "classnames";
22
import fastDeepEqual from "fast-deep-equal/react";
33
import { memo, useCallback } from "react";
4-
import { Key } from "ts-key-enum";
54
import { type UseInteractionsReturn } from "@floating-ui/react";
65
import { useObservable } from "@ngneat/use-observable";
76
import { ID_GRID_ALLDAY_ROW } from "@web/common/constants/web.constants";
@@ -28,7 +27,7 @@ const AllDayAgendaEventsComponent = ({
2827

2928
const onEnterKey = useCallback(
3029
(e: React.KeyboardEvent<HTMLDivElement>) => {
31-
if (e.key === Key.Enter) {
30+
if (e.key === "Enter") {
3231
e.preventDefault();
3332
e.stopPropagation();
3433
openEventForm();

packages/web/src/views/Forms/EventForm/DateControlsSection/DateTimeSection/DatePickers/DatePickers.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type FC } from "react";
22
import type React from "react";
3-
import { Key } from "ts-key-enum";
43
import { MONTH_DAY_YEAR } from "@core/constants/date.constants";
54
import { darken } from "@core/util/color.utils";
65
import dayjs from "@core/util/date/dayjs";
@@ -63,12 +62,12 @@ export const DatePickers: FC<Props> = ({
6362
picker: "start" | "end",
6463
e: React.KeyboardEvent<HTMLDivElement>,
6564
) => {
66-
switch (e.key) {
67-
case Key.Backspace: {
65+
switch (true) {
66+
case e.key === "Backspace": {
6867
e.stopPropagation();
6968
break;
7069
}
71-
case Key.Enter: {
70+
case e.key === "Enter": {
7271
e.stopPropagation();
7372
e.preventDefault();
7473

@@ -94,7 +93,7 @@ export const DatePickers: FC<Props> = ({
9493

9594
break;
9695
}
97-
case Key.Escape: {
96+
case e.key === "Escape": {
9897
if (isStartDatePickerOpen) {
9998
e.stopPropagation();
10099
closeStartDatePicker();
@@ -105,7 +104,7 @@ export const DatePickers: FC<Props> = ({
105104
}
106105
break;
107106
}
108-
case Key.Tab: {
107+
case e.key === "Tab": {
109108
if (isStartDatePickerOpen) {
110109
setIsStartDatePickerOpen(false);
111110
}

packages/web/src/views/Forms/EventForm/DateControlsSection/DateTimeSection/TimePicker/TimePicker.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type React from "react";
22
import ReactSelect, { type Props as RSProps } from "react-select";
3-
import { Key } from "ts-key-enum";
43
import { type SelectOption } from "@web/common/types/component.types";
54
import { type Option_Time } from "@web/common/types/util.types";
65
import { StyledTimePicker } from "./styled";
@@ -43,20 +42,20 @@ export const TimePicker = ({
4342
onKeyDown={(e) => {
4443
const key = e.key;
4544

46-
if (key === Key.Enter || key === Key.Backspace) {
45+
if (key === "Enter" || key === "Backspace") {
4746
e.stopPropagation();
4847
}
4948

50-
if (key === Key.Shift) {
49+
if (key === "Shift") {
5150
e.stopPropagation();
5251
}
5352

54-
if (key === Key.Escape) {
53+
if (key === "Escape") {
5554
setIsMenuOpen(false);
5655
e.stopPropagation();
5756
}
5857

59-
if (key === Key.Tab) {
58+
if (key === "Tab") {
6059
setIsMenuOpen(false);
6160
}
6261
}}

packages/web/src/views/Forms/EventForm/EventForm.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fastDeepEqual from "fast-deep-equal/react";
22
import { type KeyboardEvent } from "react";
33
import type React from "react";
44
import { memo, useCallback, useEffect, useRef, useState } from "react";
5-
import { Key } from "ts-key-enum";
65
import { Priorities } from "@core/constants/core.constants";
76
import { darken } from "@core/util/color.utils";
87
import dayjs from "@core/util/date/dayjs";
@@ -83,15 +82,15 @@ export const EventForm: React.FC<Omit<FormProps, "category">> = memo(
8382

8483
const keyDownHandler = useCallback(
8584
(e: globalThis.KeyboardEvent) => {
86-
if (e.key === Key.Shift) {
85+
if (e.key === "Shift") {
8786
setIsShiftKeyPressed(true);
8887
}
8988
},
9089
[_onClose],
9190
);
9291

9392
const keyUpHandler = useCallback((e: globalThis.KeyboardEvent) => {
94-
if (e.key === Key.Shift) {
93+
if (e.key === "Shift") {
9594
setIsShiftKeyPressed(false);
9695
}
9796
}, []);
@@ -151,7 +150,7 @@ export const EventForm: React.FC<Omit<FormProps, "category">> = memo(
151150
// Ignores certain keys and key combinations to prevent default behavior.
152151
// Allows some of them to be used as hotkeys
153152

154-
if (e.key === Key.Backspace) {
153+
if (e.key === "Backspace") {
155154
e.stopPropagation();
156155
}
157156

@@ -163,7 +162,7 @@ export const EventForm: React.FC<Omit<FormProps, "category">> = memo(
163162
e.preventDefault();
164163
}
165164

166-
if ((e.metaKey || e.ctrlKey) && e.key === Key.Enter) {
165+
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
167166
e.preventDefault();
168167
onSubmitForm();
169168
}

packages/web/src/views/Forms/SomedayEventForm/SomedayEventForm.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type KeyboardEvent, type MouseEvent } from "react";
22
import type React from "react";
33
import { useCallback, useRef } from "react";
4-
import { Key } from "ts-key-enum";
54
import { Priorities } from "@core/constants/core.constants";
65
import { Categories_Event } from "@core/types/event.types";
76
import { darken } from "@core/util/color.utils";
@@ -42,11 +41,11 @@ export const SomedayEventForm: React.FC<FormProps> = ({
4241
const origRecurrence = useRef(event?.recurrence).current;
4342

4443
const ignoreDelete = (e: KeyboardEvent) => {
45-
if (e.key === Key.Backspace) {
44+
if (e.key === "Backspace") {
4645
e.stopPropagation();
4746
}
4847

49-
if (e.key !== Key.Enter || e.defaultPrevented) {
48+
if (e.key !== "Enter" || e.defaultPrevented) {
5049
return;
5150
}
5251

@@ -112,12 +111,12 @@ export const SomedayEventForm: React.FC<FormProps> = ({
112111
}, [onDeleteEvent, onClose]);
113112

114113
const onKeyDown = (e: KeyboardEvent<HTMLFormElement>) => {
115-
if (e.key === Key.Backspace) {
114+
if (e.key === "Backspace") {
116115
e.stopPropagation();
117116
return;
118117
}
119118

120-
if (e.defaultPrevented || e.key !== Key.Delete) {
119+
if (e.defaultPrevented || e.key !== "Delete") {
121120
return;
122121
}
123122

packages/web/src/views/Forms/SomedayEventForm/SomedayRecurrenceSection/SomedayRecurrenceSelect/SomedayRecurrenceSelect.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ReactSelect, {
77
import { components } from "react-select";
88
import { Frequency } from "rrule";
99
import { useTheme } from "styled-components";
10-
import { Key } from "ts-key-enum";
1110
import { brighten, darken } from "@core/util/color.utils";
1211
import { theme } from "@web/common/styles/theme";
1312
import { RepeatIcon } from "@web/components/Icons/Repeat";
@@ -68,7 +67,7 @@ export const SomedayRecurrenceSelect = ({
6867
}, [menuIsOpen]);
6968

7069
const handleKeyDown = (event: React.KeyboardEvent) => {
71-
if (event.key === Key.Escape) {
70+
if (event.key === "Escape") {
7271
event.preventDefault();
7372
event.stopPropagation();
7473
onCancel?.();

0 commit comments

Comments
 (0)