Skip to content

Commit ea07b7c

Browse files
committed
Refactor: Use WizardExpertSelector in all wizard apps
1 parent 904e1ab commit ea07b7c

File tree

9 files changed

+53
-218
lines changed

9 files changed

+53
-218
lines changed

packages/tui/apps/publish/app.tsx

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,22 @@
1-
import { Box, Text, useApp, useInput } from "ink"
2-
import { useState } from "react"
3-
4-
type ExpertChoice = {
5-
name: string
6-
description?: string
7-
}
1+
import { useApp } from "ink"
2+
import { WizardExpertSelector } from "../../src/components/index.js"
3+
import type { ExpertChoice } from "../../src/types/index.js"
84

95
type PublishAppProps = {
106
experts: ExpertChoice[]
117
onSelect: (expertName: string) => void
128
}
13-
149
export function PublishApp({ experts, onSelect }: PublishAppProps) {
1510
const { exit } = useApp()
16-
const [selectedIndex, setSelectedIndex] = useState(0)
17-
useInput((input, key) => {
18-
if (key.upArrow) {
19-
setSelectedIndex((prev) => (prev > 0 ? prev - 1 : experts.length - 1))
20-
} else if (key.downArrow) {
21-
setSelectedIndex((prev) => (prev < experts.length - 1 ? prev + 1 : 0))
22-
} else if (key.return) {
23-
const expert = experts[selectedIndex]
24-
if (expert) {
25-
onSelect(expert.name)
26-
exit()
27-
}
28-
} else if (input === "q" || key.escape) {
29-
exit()
30-
}
31-
})
11+
const handleSelect = (name: string) => {
12+
onSelect(name)
13+
exit()
14+
}
3215
return (
33-
<Box flexDirection="column">
34-
<Text bold>Select an Expert to publish:</Text>
35-
<Box flexDirection="column" marginTop={1}>
36-
{experts.map((expert, index) => (
37-
<Box key={expert.name}>
38-
<Text color={index === selectedIndex ? "cyan" : undefined}>
39-
{index === selectedIndex ? "❯ " : " "}
40-
{expert.name}
41-
{expert.description && <Text dimColor> - {expert.description}</Text>}
42-
</Text>
43-
</Box>
44-
))}
45-
</Box>
46-
<Box marginTop={1}>
47-
<Text dimColor>↑↓ navigate · enter select · q quit</Text>
48-
</Box>
49-
</Box>
16+
<WizardExpertSelector
17+
title="Select an Expert to publish:"
18+
experts={experts}
19+
onSelect={handleSelect}
20+
/>
5021
)
5122
}

packages/tui/apps/publish/render.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { render } from "ink"
2+
import type { ExpertChoice } from "../../src/types/index.js"
23
import { PublishApp } from "./app.js"
34

4-
type ExpertChoice = {
5-
name: string
6-
description?: string
7-
}
8-
95
type RenderPublishSelectOptions = {
106
experts: ExpertChoice[]
117
}

packages/tui/apps/status/app.tsx

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
import { Box, Text, useApp, useInput } from "ink"
22
import { useState } from "react"
3-
4-
type ExpertChoice = {
5-
name: string
6-
description?: string
7-
}
3+
import { WizardExpertSelector } from "../../src/components/index.js"
4+
import type { ExpertChoice } from "../../src/types/index.js"
85

96
type VersionInfo = {
107
key: string
118
version: string
129
tags: string[]
1310
status: "available" | "deprecated" | "disabled"
1411
}
15-
1612
type WizardStep =
1713
| { type: "selectExpert" }
1814
| { type: "loadingVersions"; expertName: string }
1915
| { type: "selectVersion"; expertName: string; versions: VersionInfo[] }
2016
| { type: "selectStatus"; expertKey: string; currentStatus: string }
2117
| { type: "confirm"; expertKey: string; status: string; currentStatus: string }
2218
| { type: "error"; message: string }
23-
2419
type StatusWizardResult = {
2520
expertKey: string
2621
status: "available" | "deprecated" | "disabled"
2722
}
28-
2923
type StatusAppProps = {
3024
experts: ExpertChoice[]
3125
onFetchVersions: (expertName: string) => Promise<VersionInfo[]>
3226
onComplete: (result: StatusWizardResult) => void
3327
onCancel: () => void
3428
}
35-
3629
function getAvailableStatusTransitions(currentStatus: string): string[] {
3730
switch (currentStatus) {
3831
case "available":
@@ -46,50 +39,6 @@ function getAvailableStatusTransitions(currentStatus: string): string[] {
4639
}
4740
}
4841

49-
function ExpertSelector({
50-
experts,
51-
onSelect,
52-
}: {
53-
experts: ExpertChoice[]
54-
onSelect: (name: string) => void
55-
}) {
56-
const { exit } = useApp()
57-
const [selectedIndex, setSelectedIndex] = useState(0)
58-
useInput((input, key) => {
59-
if (key.upArrow) {
60-
setSelectedIndex((prev) => (prev > 0 ? prev - 1 : experts.length - 1))
61-
} else if (key.downArrow) {
62-
setSelectedIndex((prev) => (prev < experts.length - 1 ? prev + 1 : 0))
63-
} else if (key.return) {
64-
const expert = experts[selectedIndex]
65-
if (expert) {
66-
onSelect(expert.name)
67-
}
68-
} else if (input === "q" || key.escape) {
69-
exit()
70-
}
71-
})
72-
return (
73-
<Box flexDirection="column">
74-
<Text bold>Select an Expert to change status:</Text>
75-
<Box flexDirection="column" marginTop={1}>
76-
{experts.map((expert, index) => (
77-
<Box key={expert.name}>
78-
<Text color={index === selectedIndex ? "cyan" : undefined}>
79-
{index === selectedIndex ? "❯ " : " "}
80-
{expert.name}
81-
{expert.description && <Text dimColor> - {expert.description}</Text>}
82-
</Text>
83-
</Box>
84-
))}
85-
</Box>
86-
<Box marginTop={1}>
87-
<Text dimColor>↑↓ navigate · enter select · q quit</Text>
88-
</Box>
89-
</Box>
90-
)
91-
}
92-
9342
function VersionSelector({
9443
expertName,
9544
versions,
@@ -368,7 +317,13 @@ export function StatusApp({ experts, onFetchVersions, onComplete, onCancel }: St
368317
}
369318
switch (step.type) {
370319
case "selectExpert":
371-
return <ExpertSelector experts={experts} onSelect={handleExpertSelect} />
320+
return (
321+
<WizardExpertSelector
322+
title="Select an Expert to change status:"
323+
experts={experts}
324+
onSelect={handleExpertSelect}
325+
/>
326+
)
372327
case "loadingVersions":
373328
return (
374329
<Box>
@@ -417,4 +372,4 @@ export function StatusApp({ experts, onFetchVersions, onComplete, onCancel }: St
417372
}
418373
}
419374

420-
export type { ExpertChoice, VersionInfo, StatusWizardResult }
375+
export type { VersionInfo, StatusWizardResult }

packages/tui/apps/status/render.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render } from "ink"
2-
import { type ExpertChoice, StatusApp, type StatusWizardResult, type VersionInfo } from "./app.js"
2+
import type { ExpertChoice } from "../../src/types/index.js"
3+
import { StatusApp, type StatusWizardResult, type VersionInfo } from "./app.js"
34

45
type RenderStatusWizardOptions = {
56
experts: ExpertChoice[]
@@ -29,4 +30,4 @@ export async function renderStatus(
2930
})
3031
}
3132

32-
export type { ExpertChoice, VersionInfo, StatusWizardResult }
33+
export type { VersionInfo, StatusWizardResult }

packages/tui/apps/tag/app.tsx

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,32 @@
11
import { Box, Text, useApp, useInput } from "ink"
22
import { useState } from "react"
3-
4-
type ExpertChoice = {
5-
name: string
6-
description?: string
7-
}
3+
import { WizardExpertSelector } from "../../src/components/index.js"
4+
import type { ExpertChoice } from "../../src/types/index.js"
85

96
type VersionInfo = {
107
key: string
118
version: string
129
tags: string[]
1310
status: "available" | "deprecated" | "disabled"
1411
}
15-
1612
type WizardStep =
1713
| { type: "selectExpert" }
1814
| { type: "loadingVersions"; expertName: string }
1915
| { type: "selectVersion"; expertName: string; versions: VersionInfo[] }
2016
| { type: "inputTags"; expertKey: string; currentTags: string[] }
2117
| { type: "confirm"; expertKey: string; tags: string[]; currentTags: string[] }
2218
| { type: "error"; message: string }
23-
2419
type TagWizardResult = {
2520
expertKey: string
2621
tags: string[]
2722
}
28-
2923
type TagAppProps = {
3024
experts: ExpertChoice[]
3125
onFetchVersions: (expertName: string) => Promise<VersionInfo[]>
3226
onComplete: (result: TagWizardResult) => void
3327
onCancel: () => void
3428
}
3529

36-
function ExpertSelector({
37-
experts,
38-
onSelect,
39-
}: {
40-
experts: ExpertChoice[]
41-
onSelect: (name: string) => void
42-
}) {
43-
const { exit } = useApp()
44-
const [selectedIndex, setSelectedIndex] = useState(0)
45-
useInput((input, key) => {
46-
if (key.upArrow) {
47-
setSelectedIndex((prev) => (prev > 0 ? prev - 1 : experts.length - 1))
48-
} else if (key.downArrow) {
49-
setSelectedIndex((prev) => (prev < experts.length - 1 ? prev + 1 : 0))
50-
} else if (key.return) {
51-
const expert = experts[selectedIndex]
52-
if (expert) {
53-
onSelect(expert.name)
54-
}
55-
} else if (input === "q" || key.escape) {
56-
exit()
57-
}
58-
})
59-
return (
60-
<Box flexDirection="column">
61-
<Text bold>Select an Expert to tag:</Text>
62-
<Box flexDirection="column" marginTop={1}>
63-
{experts.map((expert, index) => (
64-
<Box key={expert.name}>
65-
<Text color={index === selectedIndex ? "cyan" : undefined}>
66-
{index === selectedIndex ? "❯ " : " "}
67-
{expert.name}
68-
{expert.description && <Text dimColor> - {expert.description}</Text>}
69-
</Text>
70-
</Box>
71-
))}
72-
</Box>
73-
<Box marginTop={1}>
74-
<Text dimColor>↑↓ navigate · enter select · q quit</Text>
75-
</Box>
76-
</Box>
77-
)
78-
}
79-
8030
function VersionSelector({
8131
expertName,
8232
versions,
@@ -343,7 +293,13 @@ export function TagApp({ experts, onFetchVersions, onComplete, onCancel }: TagAp
343293
}
344294
switch (step.type) {
345295
case "selectExpert":
346-
return <ExpertSelector experts={experts} onSelect={handleExpertSelect} />
296+
return (
297+
<WizardExpertSelector
298+
title="Select an Expert to tag:"
299+
experts={experts}
300+
onSelect={handleExpertSelect}
301+
/>
302+
)
347303
case "loadingVersions":
348304
return (
349305
<Box>
@@ -392,4 +348,4 @@ export function TagApp({ experts, onFetchVersions, onComplete, onCancel }: TagAp
392348
}
393349
}
394350

395-
export type { ExpertChoice, VersionInfo, TagWizardResult }
351+
export type { VersionInfo, TagWizardResult }

packages/tui/apps/tag/render.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render } from "ink"
2-
import { type ExpertChoice, TagApp, type TagWizardResult, type VersionInfo } from "./app.js"
2+
import type { ExpertChoice } from "../../src/types/index.js"
3+
import { TagApp, type TagWizardResult, type VersionInfo } from "./app.js"
34

45
type RenderTagWizardOptions = {
56
experts: ExpertChoice[]
@@ -27,4 +28,4 @@ export async function renderTag(options: RenderTagWizardOptions): Promise<TagWiz
2728
})
2829
}
2930

30-
export type { ExpertChoice, VersionInfo, TagWizardResult }
31+
export type { VersionInfo, TagWizardResult }

0 commit comments

Comments
 (0)