|
1 | 1 | import type { ActiveTutorialNoErrorsState } from "@cursorless/common"; |
2 | | -import type { FunctionComponent } from "preact"; |
3 | 2 | import type { WebviewApi } from "vscode-webview"; |
4 | 3 | import { ArrowLeftIcon } from "./ArrowLeftIcon"; |
5 | 4 | import { ArrowRightIcon } from "./ArrowRightIcon"; |
6 | 5 | import { CloseIcon } from "./CloseIcon"; |
7 | 6 | import { Command } from "./Command"; |
8 | 7 | import { ProgressBar } from "./ProgressBar"; |
9 | 8 |
|
10 | | -interface TutorialStepProps { |
| 9 | +interface Props { |
11 | 10 | state: ActiveTutorialNoErrorsState; |
12 | 11 | vscode: WebviewApi<undefined>; |
13 | 12 | } |
14 | 13 |
|
15 | | -export const TutorialStep: FunctionComponent<TutorialStepProps> = ({ |
16 | | - state, |
17 | | - vscode, |
18 | | -}) => { |
19 | | - return ( |
20 | | - <div> |
21 | | - <div className="mt-2 mb-2 flex items-center gap-[0.2em]"> |
| 14 | +export function TutorialStep({ state, vscode }: Props) { |
| 15 | + const renderProgress = () => { |
| 16 | + return ( |
| 17 | + <div className="mt-2 mb-2 d-flex align-items-center gap-1"> |
22 | 18 | <ProgressBar |
23 | 19 | currentStep={state.stepNumber} |
24 | 20 | stepCount={state.stepCount} |
25 | 21 | /> |
26 | 22 | <button |
| 23 | + className="btn btn-link p-0 d-inline-flex" |
27 | 24 | onClick={() => |
28 | 25 | vscode.postMessage({ |
29 | 26 | type: "list", |
30 | 27 | }) |
31 | 28 | } |
32 | 29 | > |
33 | | - <span> |
34 | | - <CloseIcon /> |
35 | | - </span> |
| 30 | + <CloseIcon /> |
36 | 31 | </button> |
37 | 32 | </div> |
38 | | - {state.preConditionsMet ? ( |
39 | | - <> |
40 | | - {state.stepContent.map((paragraph, i) => ( |
41 | | - <div key={i} className="mt-1"> |
42 | | - {paragraph.map((fragment, j) => { |
43 | | - switch (fragment.type) { |
44 | | - case "string": |
45 | | - return <span key={j}>{fragment.value}</span>; |
46 | | - case "command": |
47 | | - return <Command spokenForm={fragment.value} />; |
48 | | - case "term": |
49 | | - return <span>"{fragment.value}"</span>; |
50 | | - default: { |
51 | | - // Ensure we handle all cases |
52 | | - const _unused: never = fragment; |
53 | | - } |
54 | | - } |
55 | | - })} |
56 | | - </div> |
57 | | - ))} |
58 | | - <div className="mt-2 flex w-full flex-row justify-between"> |
59 | | - <button |
60 | | - onClick={() => |
61 | | - vscode.postMessage({ |
62 | | - type: "previous", |
63 | | - }) |
64 | | - } |
65 | | - > |
66 | | - <span> |
67 | | - <ArrowLeftIcon size={12} /> |
68 | | - </span> |
69 | | - </button> |
70 | | - <span className="text-2xs"> |
71 | | - {state.stepNumber + 1} / {state.stepCount}{" "} |
72 | | - </span> |
73 | | - <button |
74 | | - onClick={() => |
75 | | - vscode.postMessage({ |
76 | | - type: "next", |
77 | | - }) |
78 | | - } |
79 | | - > |
80 | | - <span> |
81 | | - <ArrowRightIcon size={12} /> |
82 | | - </span> |
83 | | - </button> |
84 | | - </div> |
85 | | - </> |
86 | | - ) : ( |
| 33 | + ); |
| 34 | + }; |
| 35 | + |
| 36 | + const renderStepContent = () => { |
| 37 | + if (!state.preConditionsMet) { |
| 38 | + return ( |
87 | 39 | <> |
88 | 40 | <div>Whoops! Looks like you've stepped off the beaten path.</div> |
89 | 41 | <div className="mt-1"> |
90 | 42 | Feel free to keep playing, then say{" "} |
91 | 43 | <Command spokenForm="tutorial resume" /> to resume the tutorial. |
92 | 44 | </div> |
93 | 45 | </> |
94 | | - )} |
95 | | - </div> |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + return ( |
| 50 | + <> |
| 51 | + {state.stepContent.map((paragraph, i) => ( |
| 52 | + <div key={i} className="mt-1"> |
| 53 | + {paragraph.map((fragment, j) => { |
| 54 | + switch (fragment.type) { |
| 55 | + case "string": |
| 56 | + return <span key={j}>{fragment.value}</span>; |
| 57 | + case "command": |
| 58 | + return <Command spokenForm={fragment.value} />; |
| 59 | + case "term": |
| 60 | + return <span>"{fragment.value}"</span>; |
| 61 | + default: { |
| 62 | + // Ensure we handle all cases |
| 63 | + const _unused: never = fragment; |
| 64 | + } |
| 65 | + } |
| 66 | + })} |
| 67 | + </div> |
| 68 | + ))} |
| 69 | + |
| 70 | + <div className="mt-2 d-flex w-100 align-items-center justify-content-between"> |
| 71 | + <button |
| 72 | + className="btn btn-link p-0 d-inline-flex" |
| 73 | + onClick={() => |
| 74 | + vscode.postMessage({ |
| 75 | + type: "previous", |
| 76 | + }) |
| 77 | + } |
| 78 | + > |
| 79 | + <ArrowLeftIcon size={12} /> |
| 80 | + </button> |
| 81 | + <span className="tutorial-step-counter"> |
| 82 | + {state.stepNumber + 1} / {state.stepCount}{" "} |
| 83 | + </span> |
| 84 | + <button |
| 85 | + className="btn btn-link p-0 d-inline-flex" |
| 86 | + onClick={() => |
| 87 | + vscode.postMessage({ |
| 88 | + type: "next", |
| 89 | + }) |
| 90 | + } |
| 91 | + > |
| 92 | + <ArrowRightIcon size={12} /> |
| 93 | + </button> |
| 94 | + </div> |
| 95 | + </> |
| 96 | + ); |
| 97 | + }; |
| 98 | + |
| 99 | + return ( |
| 100 | + <> |
| 101 | + {renderProgress()} |
| 102 | + {renderStepContent()} |
| 103 | + </> |
96 | 104 | ); |
97 | | -}; |
| 105 | +} |
0 commit comments