Skip to content

fix continue progress #153

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 1 commit into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class Channel implements Channel {
const actionType: string = typeof action === 'string' ? action : action.type
switch (actionType) {
case 'TEST_PASS':
// update local storage stepProgress
const progress = this.context.progress.setStepComplete(action.payload.stepId)
const tutorial = this.context.tutorial.get()
if (!tutorial) {
throw new Error('Error with current tutorial')
}
// update local storage stepProgress
const progress = this.context.progress.setStepComplete(tutorial.version.data, action.payload.stepId)
this.context.position.setPositionFromProgress(tutorial, progress)
saveCommit()
}
Expand Down
7 changes: 3 additions & 4 deletions src/channel/state/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ class Position {
throw new Error('Error setting position from progress')
}

// get level
const { levels } = tutorial.version.data

const lastLevelIndex: number | undefined = levels.findIndex((l: G.Level) => !progress.levels[l.id])

if (lastLevelIndex >= levels.length) {
throw new Error('Error setting progress level')
}
const currentLevel: G.Level = levels[lastLevelIndex]

// get step
const currentLevel: G.Level = levels[lastLevelIndex]
const { steps } = currentLevel

const lastStepIndex: number | undefined = steps.findIndex((s: G.Step) => !progress.steps[s.id])
if (lastStepIndex >= steps.length) {
throw new Error('Error setting progress step')
Expand Down
18 changes: 16 additions & 2 deletions src/channel/state/Progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ class Progress {
public reset = () => {
this.set(defaultValue)
}
public setStepComplete = (stepId: string): CR.Progress => {
public setStepComplete = (tutorialData: G.TutorialData, stepId: string): CR.Progress => {
const next = this.value
// mark step complete
next.steps[stepId] = true

// TODO validate if progress is complete for a level or tutorial
const currentLevel = tutorialData.levels.find(l => l.steps.find(s => s.id === stepId))
if (!currentLevel) {
throw new Error(`setStepComplete level not found for stepId ${stepId}`)
}

if (currentLevel.steps[currentLevel.steps.length - 1]) {
// final step for level is complete
next.levels[currentLevel.id] = true

if (tutorialData.levels[tutorialData.levels.length - 1].id === currentLevel.id) {
//final level complete so tutorial is complete
next.complete = true
}
}

return this.set(next)
}
Expand Down
4 changes: 0 additions & 4 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as T from 'typings'
import * as vscode from 'vscode'
import notify from '../services/notify'
import createTestRunner, { Payload } from '../services/testRunner'
import createWebView from '../webview'

Expand All @@ -27,9 +26,6 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
return {
// initialize
[COMMANDS.START]: async () => {
// TODO replace with a prompt to open a workspace
// await isEmptyWorkspace()

let webviewState: 'INITIALIZING' | 'RESTARTING'
if (!webview) {
webviewState = 'INITIALIZING'
Expand Down