Skip to content

Feature/new continue #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
setup continue path
  • Loading branch information
ShMcK committed Jun 10, 2019
commit cb9f82ed445814db6b8d81dfde829ee8c571c4b5
18 changes: 1 addition & 17 deletions src/editor/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import tutorial from '../../state/context/tutorials/basic'

const COMMANDS = {
START: 'coderoad.start',
NEW_OR_CONTINUE: 'coderoad.new_or_continue',
TUTORIAL_LAUNCH: 'coderoad.tutorial_launch',
OPEN_WEBVIEW: 'coderoad.open_webview',
SEND_STATE: 'coderoad.send_state',
Expand Down Expand Up @@ -45,23 +44,8 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.One) => {
webview.createOrShow(column);
},
// launch with continue or new
[COMMANDS.NEW_OR_CONTINUE]: async () => {
// verify that the user has a tutorial & progress
// verify git is setup with a coderoad remote
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
storage.getTutorial(),
storage.getProgress(),
git.gitVersion(),
git.gitCheckRemoteExists(),
])
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
console.log('canContinue', canContinue)
// if a tutorial exists, 'CONTINUE'
// otherwise start from 'NEW'
machine.send(canContinue ? 'CONTINUE' : 'NEW')
},
// launch a new tutorial
// NOTE: may be better to move into action as logic is primarily non-vscode
[COMMANDS.TUTORIAL_LAUNCH]: async () => {
console.log('launch tutorial')

Expand Down
23 changes: 21 additions & 2 deletions src/state/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { assign } from 'xstate'
// NOTE: codesmell - importing machine
import { machine } from '../../extension'
import * as CR from 'typings'
import * as vscode from 'vscode'
import * as storage from '../../services/storage'
import * as git from '../../services/git'

let initialTutorial: CR.Tutorial | undefined
let initialProgress: CR.Progress = {
Expand All @@ -15,8 +19,23 @@ export default {
console.log('execute coderoad.open_webview')
vscode.commands.executeCommand('coderoad.open_webview')
},
newOrContinue() {
vscode.commands.executeCommand('coderoad.new_or_continue')
async newOrContinue() {
// verify that the user has a tutorial & progress
// verify git is setup with a coderoad remote
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
storage.getTutorial(),
storage.getProgress(),
git.gitVersion(),
git.gitCheckRemoteExists(),
])
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)

if (canContinue) {
initialTutorial = tutorial
initialProgress = progress
}

machine.send(canContinue ? 'CONTINUE' : 'NEW')
},
tutorialLaunch() {
vscode.commands.executeCommand('coderoad.tutorial_launch')
Expand Down
2 changes: 1 addition & 1 deletion src/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const machine = Machine<

},
ContinueTutorial: {
onEntry: 'tutorialContinue',
onEntry: ['tutorialContinue'],
on: {
TUTORIAL_START: {
target: 'Tutorial.LoadNext',
Expand Down
4 changes: 2 additions & 2 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ const Routes = ({ state }: Props) => {
return (
<div>
<Cond state={state} path="SelectTutorial.Startup">
<div style={{ backgroundColor: 'red' }}>
<div>
<h3>Starting...</h3>
</div>
</Cond>
<Cond state={state} path="SelectTutorial.NewTutorial">
<NewPage />
</Cond>
<Cond state={state} path="SelectTutorial.ContinueTutorial">
<ContinuePage />
<ContinuePage />
</Cond>
<Cond state={state} path="Tutorial">
<TutorialPage />
Expand Down