Skip to content

Commit cb9f82e

Browse files
committed
setup continue path
1 parent 314e71b commit cb9f82e

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

src/editor/commands/index.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import tutorial from '../../state/context/tutorials/basic'
99

1010
const COMMANDS = {
1111
START: 'coderoad.start',
12-
NEW_OR_CONTINUE: 'coderoad.new_or_continue',
1312
TUTORIAL_LAUNCH: 'coderoad.tutorial_launch',
1413
OPEN_WEBVIEW: 'coderoad.open_webview',
1514
SEND_STATE: 'coderoad.send_state',
@@ -45,23 +44,8 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
4544
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.One) => {
4645
webview.createOrShow(column);
4746
},
48-
// launch with continue or new
49-
[COMMANDS.NEW_OR_CONTINUE]: async () => {
50-
// verify that the user has a tutorial & progress
51-
// verify git is setup with a coderoad remote
52-
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
53-
storage.getTutorial(),
54-
storage.getProgress(),
55-
git.gitVersion(),
56-
git.gitCheckRemoteExists(),
57-
])
58-
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
59-
console.log('canContinue', canContinue)
60-
// if a tutorial exists, 'CONTINUE'
61-
// otherwise start from 'NEW'
62-
machine.send(canContinue ? 'CONTINUE' : 'NEW')
63-
},
6447
// launch a new tutorial
48+
// NOTE: may be better to move into action as logic is primarily non-vscode
6549
[COMMANDS.TUTORIAL_LAUNCH]: async () => {
6650
console.log('launch tutorial')
6751

src/state/actions/index.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { assign } from 'xstate'
2+
// NOTE: codesmell - importing machine
3+
import { machine } from '../../extension'
24
import * as CR from 'typings'
35
import * as vscode from 'vscode'
6+
import * as storage from '../../services/storage'
7+
import * as git from '../../services/git'
48

59
let initialTutorial: CR.Tutorial | undefined
610
let initialProgress: CR.Progress = {
@@ -15,8 +19,23 @@ export default {
1519
console.log('execute coderoad.open_webview')
1620
vscode.commands.executeCommand('coderoad.open_webview')
1721
},
18-
newOrContinue() {
19-
vscode.commands.executeCommand('coderoad.new_or_continue')
22+
async newOrContinue() {
23+
// verify that the user has a tutorial & progress
24+
// verify git is setup with a coderoad remote
25+
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
26+
storage.getTutorial(),
27+
storage.getProgress(),
28+
git.gitVersion(),
29+
git.gitCheckRemoteExists(),
30+
])
31+
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
32+
33+
if (canContinue) {
34+
initialTutorial = tutorial
35+
initialProgress = progress
36+
}
37+
38+
machine.send(canContinue ? 'CONTINUE' : 'NEW')
2039
},
2140
tutorialLaunch() {
2241
vscode.commands.executeCommand('coderoad.tutorial_launch')

src/state/machine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const machine = Machine<
4949

5050
},
5151
ContinueTutorial: {
52-
onEntry: 'tutorialContinue',
52+
onEntry: ['tutorialContinue'],
5353
on: {
5454
TUTORIAL_START: {
5555
target: 'Tutorial.LoadNext',

web-app/src/Routes.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const Routes = ({ state }: Props) => {
1515
return (
1616
<div>
1717
<Cond state={state} path="SelectTutorial.Startup">
18-
<div style={{ backgroundColor: 'red' }}>
18+
<div>
1919
<h3>Starting...</h3>
2020
</div>
2121
</Cond>
2222
<Cond state={state} path="SelectTutorial.NewTutorial">
2323
<NewPage />
2424
</Cond>
2525
<Cond state={state} path="SelectTutorial.ContinueTutorial">
26-
<ContinuePage />
26+
<ContinuePage />
2727
</Cond>
2828
<Cond state={state} path="Tutorial">
2929
<TutorialPage />

0 commit comments

Comments
 (0)