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
initialize new tutorial
  • Loading branch information
ShMcK committed Jun 9, 2019
commit 5a02b7987e7c2eb39ec2a8fa9d9b13ba75d2f030
33 changes: 29 additions & 4 deletions src/editor/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import * as vscode from 'vscode'
import { join } from 'path'
import { setStorage } from '../storage'
import ReactWebView from '../ReactWebView'
import { isEmptyWorkspace } from '../workspace'
import * as CR from 'typings'
// TODO: replace with actual tutorial loading later
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',
SEND_DATA: 'coderoad.send_data',
Expand All @@ -20,12 +24,13 @@ interface CreateCommandProps {
machine: CR.StateMachine,
storage: any,
git: any
position: any
}

// React panel webview
let webview: any;

export const createCommands = ({ context, machine, storage, git }: CreateCommandProps) => ({
export const createCommands = ({ context, machine, storage, git, position }: CreateCommandProps) => ({
// initialize
[COMMANDS.START]: () => {
// set local storage workspace
Expand All @@ -36,6 +41,11 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
console.log('webview', webview.panel.webview.postMessage)
machine.activate()
},
// open React webview
[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
Expand All @@ -51,9 +61,24 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
// otherwise start from 'NEW'
machine.send(canContinue ? 'CONTINUE' : 'NEW')
},
// open React webview
[COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.One) => {
webview.createOrShow(column);
// launch a new tutorial
[COMMANDS.TUTORIAL_LAUNCH]: async () => {
console.log('launch tutorial')

await isEmptyWorkspace()

await git.gitInitIfNotExists()

// TODO: use actual tutorial repo
await Promise.all([git.gitSetupRemote(tutorial.meta.repo), storage.setTutorial(tutorial), storage.resetProgress()])

// TODO: refactor to allow client to call initialization
const pos: CR.Position = await position.getInitial(tutorial)

// eslint-disable-next-line
const { steps } = tutorial.data
const { setup } = steps[pos.stepId].actions
await git.gitLoadCommits(setup)
},
// open a file
[COMMANDS.OPEN_FILE]: async (relativeFilePath: string) => {
Expand Down
2 changes: 2 additions & 0 deletions src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as CR from 'typings'
import { createCommands } from './commands'
import * as storage from '../services/storage'
import * as git from '../services/git'
import * as position from '../services/position'

interface Props {
machine: CR.StateMachine,
Expand Down Expand Up @@ -33,6 +34,7 @@ class Editor {
machine: this.machine,
storage,
git,
position,
})
for (const cmd in commands) {
const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd])
Expand Down
19 changes: 11 additions & 8 deletions src/state/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ let initialProgress: CR.Progress = {
}

export default {
tutorialLoad: assign({
createWebview() {
console.log('execute coderoad.open_webview')
vscode.commands.executeCommand('coderoad.open_webview')
},
newOrContinue() {
vscode.commands.executeCommand('coderoad.new_or_continue')
},
tutorialLaunch() {
vscode.commands.executeCommand('coderoad.tutorial_launch')
},
tutorialContinue: assign({
// load initial data, progress & position
data(): CR.TutorialData {
console.log('ACTION: tutorialLoad.data')
Expand Down Expand Up @@ -45,11 +55,4 @@ export default {
return position
}
}),
createWebview() {
console.log('execute coderoad.open_webview')
vscode.commands.executeCommand('coderoad.open_webview')
},
newOrContinue() {
vscode.commands.executeCommand('coderoad.new_or_continue')
}
}
2 changes: 1 addition & 1 deletion src/state/context/tutorials/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const basic: CR.Tutorial = {
id: 'tutorialId',
meta: {
version: '0.1.0',
repo: 'https://github.com/ShMcK/coderoad-vscode.git',
repo: 'https://github.com/ShMcK/coderoad-tutorial-basic.git',
createdBy: 'shmck',
createdAt: 'Sat, 11 May 2019 18:25:24 GMT',
updatedBy: 'shmck',
Expand Down
3 changes: 2 additions & 1 deletion src/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const machine = Machine<
},
},
InitializeTutorial: {
onEntry: ['tutorialLaunch'],
on: {
TUTORIAL_LOADED: 'Tutorial'
}
Expand All @@ -48,7 +49,7 @@ export const machine = Machine<

},
ContinueTutorial: {
onEntry: 'tutorialLoad',
onEntry: 'tutorialContinue',
on: {
TUTORIAL_START: {
target: 'Tutorial.LoadNext',
Expand Down