Skip to content

Commit 043e35f

Browse files
committed
refactor: extract repeated event value extraction pattern into helper function
- Add extractEventValue helper function to reduce code duplication - Replace 5 occurrences of repeated pattern with helper function call - Improves code readability and maintainability Addresses ellipsi-bot feedback about repeated pattern: (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value
1 parent 3b726a2 commit 043e35f

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

webview-ui/src/components/modes/ModesView.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ function getGroupName(group: GroupEntry): ToolGroup {
6363
return Array.isArray(group) ? group[0] : group
6464
}
6565

66+
// Helper function to extract value from VSCode events (CustomEvent or regular Event)
67+
function extractEventValue(e: Event | React.FormEvent<HTMLElement>): string {
68+
return (e as unknown as CustomEvent)?.detail?.target?.value || ((e as any).target as HTMLTextAreaElement).value
69+
}
70+
6671
const ModesView = ({ onDone }: ModesViewProps) => {
6772
const { t } = useAppTranslation()
6873

@@ -859,9 +864,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
859864
setLocalModeRoleDefinition(currentValue)
860865
}}
861866
onChange={(e) => {
862-
const value =
863-
(e as unknown as CustomEvent)?.detail?.target?.value ||
864-
((e as any).target as HTMLTextAreaElement).value
867+
const value = extractEventValue(e)
865868
setLocalModeRoleDefinition(value)
866869
}}
867870
onBlur={() => {
@@ -942,9 +945,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
942945
setLocalModeDescription(currentValue || "")
943946
}}
944947
onChange={(e) => {
945-
const value =
946-
(e as unknown as CustomEvent)?.detail?.target?.value ||
947-
((e as any).target as HTMLTextAreaElement).value
948+
const value = extractEventValue(e)
948949
setLocalModeDescription(value)
949950
}}
950951
onBlur={() => {
@@ -1026,9 +1027,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
10261027
setLocalModeWhenToUse(currentValue || "")
10271028
}}
10281029
onChange={(e) => {
1029-
const value =
1030-
(e as unknown as CustomEvent)?.detail?.target?.value ||
1031-
((e as any).target as HTMLTextAreaElement).value
1030+
const value = extractEventValue(e)
10321031
setLocalModeWhenToUse(value)
10331032
}}
10341033
onBlur={() => {
@@ -1214,9 +1213,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
12141213
setLocalModeCustomInstructions(currentValue || "")
12151214
}}
12161215
onChange={(e) => {
1217-
const value =
1218-
(e as unknown as CustomEvent)?.detail?.target?.value ||
1219-
((e as any).target as HTMLTextAreaElement).value
1216+
const value = extractEventValue(e)
12201217
setLocalModeCustomInstructions(value)
12211218
}}
12221219
onBlur={() => {
@@ -1431,9 +1428,7 @@ const ModesView = ({ onDone }: ModesViewProps) => {
14311428
resize="vertical"
14321429
value={customInstructions || ""}
14331430
onChange={(e) => {
1434-
const value =
1435-
(e as unknown as CustomEvent)?.detail?.target?.value ||
1436-
((e as any).target as HTMLTextAreaElement).value
1431+
const value = extractEventValue(e)
14371432
setCustomInstructions(value || undefined)
14381433
vscode.postMessage({
14391434
type: "customInstructions",

0 commit comments

Comments
 (0)