-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcomeViewProvider.tsx
More file actions
280 lines (259 loc) · 9.78 KB
/
Copy pathWelcomeViewProvider.tsx
File metadata and controls
280 lines (259 loc) · 9.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import { useCallback, useState } from "react"
import type { ProviderSettings } from "@shofer/types"
import { useExtensionState } from "@src/context/ExtensionStateContext"
import { validateApiConfiguration } from "@src/utils/validate"
import { vscode } from "@src/utils/vscode"
import { useAppTranslation } from "@src/i18n/TranslationContext"
import { Button } from "@src/components/ui"
import { cn } from "@src/lib/utils"
import ApiOptions from "../settings/ApiOptions"
import { Tab, TabContent } from "../common/Tab"
import { DiscordIcon, RedditIcon, XIcon } from "../common/BrandIcons"
import ShoferHero from "./ShoferHero"
import { Trans } from "react-i18next"
import {
ArrowLeft,
ArrowRight,
Github,
GraduationCap,
Heart,
KeyRound,
MessageSquarePlus,
Store,
X,
} from "lucide-react"
const WelcomeViewProvider = ({ onClose }: { onClose?: () => void }) => {
const { apiConfiguration, currentApiConfigName, setApiConfiguration, uriScheme } = useExtensionState()
const { t } = useAppTranslation()
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined)
const [showConfigureProvider, setShowConfigureProvider] = useState(false)
// Memoize the setApiConfigurationField function to pass to ApiOptions
const setApiConfigurationFieldForApiOptions = useCallback(
<K extends keyof ProviderSettings>(field: K, value: ProviderSettings[K]) => {
setApiConfiguration({ [field]: value })
},
[setApiConfiguration],
)
const handleNavigateToConfigureProvider = useCallback(() => {
setShowConfigureProvider(true)
}, [])
const handleFinish = useCallback(() => {
const error = apiConfiguration ? validateApiConfiguration(apiConfiguration) : undefined
if (error) {
setErrorMessage(error)
return
}
setErrorMessage(undefined)
// On first run there is no profile yet, so currentApiConfigName is empty
// and the host's upsert handler (gated on a non-empty name) would no-op.
// Default to the "default" profile so the selection is saved and activated.
vscode.postMessage({
type: "upsertApiConfiguration",
text: currentApiConfigName || "default",
apiConfiguration,
})
// Return to the landing screen (the steps) rather than leaving the form —
// the welcome panel now persists until the user closes it, so they can
// follow steps 2 and 3.
setShowConfigureProvider(false)
}, [apiConfiguration, currentApiConfigName])
const handleBackToLanding = useCallback(() => {
setShowConfigureProvider(false)
setErrorMessage(undefined)
}, [])
// Landing screen
if (!showConfigureProvider) {
// Shared link style so all three step CTAs look identical.
const ctaClass =
"mt-1 inline-flex w-fit cursor-pointer items-center gap-1 border-none bg-transparent p-0 text-sm font-medium text-vscode-textLink-foreground hover:underline"
const steps = [
{
icon: KeyRound,
title: t("welcome:landing.steps.connect.title"),
description: t("welcome:landing.steps.connect.description"),
action: (
<button onClick={handleNavigateToConfigureProvider} className={ctaClass}>
{t("welcome:landing.getStarted")}
<ArrowRight className="size-3.5" />
</button>
),
},
{
icon: GraduationCap,
title: t("welcome:landing.steps.learn.title"),
description: t("welcome:landing.steps.learn.description"),
action: (
<button onClick={() => vscode.postMessage({ type: "walkthroughOpen" })} className={ctaClass}>
{t("welcome:landing.steps.learn.cta")}
<ArrowRight className="size-3.5" />
</button>
),
},
{
icon: MessageSquarePlus,
title: t("welcome:landing.steps.prompt.title"),
description: t("welcome:landing.steps.prompt.description"),
action: (
<button
onClick={() => window.postMessage({ type: "action", action: "launcherButtonClicked" }, "*")}
className={ctaClass}>
{t("welcome:landing.steps.prompt.cta")}
<ArrowRight className="size-3.5" />
</button>
),
},
]
return (
<Tab>
<TabContent className="relative flex flex-col gap-5 p-6 justify-center">
{onClose && (
<button
onClick={onClose}
aria-label={t("welcome:close")}
className="absolute right-3 top-3 inline-flex size-7 cursor-pointer items-center justify-center rounded-md border-none bg-transparent text-vscode-descriptionForeground hover:bg-[rgba(255,255,255,0.07)] hover:text-vscode-foreground">
<X className="size-4" />
</button>
)}
<ShoferHero />
<div className="flex flex-col gap-1">
<h2 className="mt-0 mb-0 text-xl">{t("welcome:landing.greeting")}</h2>
<p className="m-0 text-sm leading-normal text-vscode-descriptionForeground">
<Trans i18nKey="welcome:landing.introduction" />
</p>
</div>
<ol className="m-0 flex list-none flex-col p-0">
{steps.map((step, i) => {
const Icon = step.icon
const isLast = i === steps.length - 1
return (
<li key={i} className="flex gap-3">
{/* Timeline column: numbered badge + connecting line */}
<div className="flex flex-col items-center self-stretch">
<div className="flex size-8 flex-shrink-0 items-center justify-center rounded-full bg-vscode-button-background text-sm font-semibold text-vscode-button-foreground shadow-sm">
{i + 1}
</div>
{!isLast && <div className="my-1 w-px flex-1 bg-vscode-input-border" />}
</div>
{/* Content */}
<div className={cn("flex flex-col gap-1", isLast ? "pb-1" : "pb-5")}>
<div className="flex items-center gap-2 text-vscode-foreground">
<Icon className="size-4 text-vscode-descriptionForeground" />
<span className="font-medium">{step.title}</span>
</div>
<p className="m-0 text-sm leading-snug text-vscode-descriptionForeground">
{step.description}
</p>
{step.action}
</div>
</li>
)
})}
</ol>
<div className="absolute bottom-6 left-6">
<button
onClick={() => vscode.postMessage({ type: "importSettings" })}
className="cursor-pointer border-none bg-transparent p-0 text-sm text-vscode-descriptionForeground hover:text-vscode-foreground hover:underline">
{t("welcome:importSettings")}
</button>
</div>
{/* External links: GitHub star, Marketplace rating, sponsor (row 1); Discord, Reddit, X (row 2). */}
<div className="absolute bottom-5 right-5 flex flex-col items-end gap-1.5">
<div className="flex items-center gap-2">
<span className="text-xs text-vscode-descriptionForeground">
{t("welcome:links.encourage")}
</span>
<div className="flex items-center gap-0.5">
{[
{
icon: Github,
url: "https://github.com/shofer-dev/shofer",
label: t("welcome:links.starGithub"),
},
{
icon: Store,
url: "https://marketplace.visualstudio.com/items?itemName=shoferdev.shofer",
label: t("welcome:links.starMarketplace"),
},
{
icon: Heart,
url: "https://github.com/sponsors/alsterg",
label: t("welcome:links.sponsor"),
},
].map(({ icon: Icon, url, label }) => (
<button
key={url}
title={label}
aria-label={label}
onClick={() => vscode.postMessage({ type: "openExternal", url })}
className="inline-flex size-7 cursor-pointer items-center justify-center rounded-md border-none bg-transparent text-vscode-descriptionForeground hover:bg-[rgba(255,255,255,0.07)] hover:text-vscode-foreground">
<Icon className="size-4" />
</button>
))}
</div>
</div>
<div className="flex items-center gap-2">
<span className="text-xs text-vscode-descriptionForeground">
{t("welcome:links.conversationMessage")}
</span>
<div className="flex items-center gap-0.5">
{[
{
icon: DiscordIcon,
url: "https://discord.gg/shofer",
label: t("welcome:links.discord"),
},
{
icon: RedditIcon,
url: "https://www.reddit.com/r/Shofer_dev/",
label: t("welcome:links.reddit"),
},
{ icon: XIcon, url: "https://x.com/", label: t("welcome:links.x") },
].map(({ icon: Icon, url, label }) => (
<button
key={url}
title={label}
aria-label={label}
onClick={() => vscode.postMessage({ type: "openExternal", url })}
className="inline-flex size-7 cursor-pointer items-center justify-center rounded-md border-none bg-transparent text-vscode-descriptionForeground hover:bg-[rgba(255,255,255,0.07)] hover:text-vscode-foreground">
<Icon className="size-4" />
</button>
))}
</div>
</div>
</div>
</TabContent>
</Tab>
)
}
// Configure Provider screen — 3rd-party provider API key entry
return (
<Tab>
<TabContent className="flex flex-col gap-4 p-6 justify-center">
<h2 className="mt-0 mb-0 text-xl">{t("welcome:providerSignup.useAnotherProvider")}</h2>
<p className="text-base text-vscode-foreground">
{t("welcome:providerSignup.useAnotherProviderDescription")}
</p>
<div>
<ApiOptions
apiConfiguration={apiConfiguration || {}}
uriScheme={uriScheme}
setApiConfigurationField={setApiConfigurationFieldForApiOptions}
fromWelcomeView
errorMessage={errorMessage}
setErrorMessage={setErrorMessage}
/>
</div>
<div className="flex gap-2">
<Button onClick={handleBackToLanding} variant="secondary">
<ArrowLeft className="size-4" />
{t("welcome:providerSignup.goBack")}
</Button>
<Button onClick={handleFinish} variant="primary">
{t("welcome:providerSignup.finish")} →
</Button>
</div>
</TabContent>
</Tab>
)
}
export default WelcomeViewProvider