-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathApp.tsx
More file actions
100 lines (92 loc) · 2.65 KB
/
App.tsx
File metadata and controls
100 lines (92 loc) · 2.65 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
import type { TutorialState } from "@cursorless/lib-common";
import { useEffect, useState } from "preact/hooks";
import type { WebviewApi } from "vscode-webview";
import { Command } from "./Command";
import { TutorialStep } from "./TutorialStep";
interface Props {
vscode: WebviewApi<undefined>;
}
export function App({ vscode }: Props) {
const [state, setState] = useState<TutorialState>();
useEffect(() => {
// Handle messages sent from the extension to the webview
window.addEventListener(
"message",
({ data: newState }: { data: TutorialState }) => {
setState(newState);
},
);
vscode.postMessage({ type: "getInitialState" });
}, [vscode]);
if (state == null) {
// Just show nothing while we're waiting for initial state
return null;
}
switch (state.type) {
case "pickingTutorial":
return (
<div>
<p>
To start a tutorial, say <Command spokenForm="tutorial <number>" />,
or click one of the following tutorials:
</p>
<ol className="mt-2">
{state.tutorials.map((tutorial) => (
<li key={tutorial.id} className="mb-1">
<button
className="btn btn-link p-0 text-decoration-none"
onClick={() =>
vscode.postMessage({
type: "start",
tutorialId: tutorial.id,
})
}
>
<TutorialProgressIndicator
currentStep={tutorial.currentStep}
stepCount={tutorial.stepCount}
/>
{tutorial.title}
</button>
</li>
))}
</ol>
</div>
);
case "doingTutorial":
if (state.hasErrors) {
return (
<div>
<h1 className="has-error">Error</h1>
{state.requiresTalonUpdate && (
<p>
Please{" "}
<a
href="https://www.cursorless.org/docs/user/updating/#updating-the-talon-side"
className="link-primary"
>
update cursorless-talon
</a>
</p>
)}
</div>
);
}
return <TutorialStep state={state} vscode={vscode} />;
}
}
function TutorialProgressIndicator({
currentStep,
stepCount,
}: {
currentStep: number;
stepCount: number;
}) {
if (currentStep === 0) {
return null;
}
if (currentStep === stepCount - 1) {
return <span className="me-1">✅</span>;
}
return <span className="me-1">🕗</span>;
}