Skip to content

Fix/continue #34

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 3 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ensure clearing of old progress on new
  • Loading branch information
ShMcK committed Sep 23, 2019
commit 19d819c8da2dce7f9cb803a7902772b465f79d6d
5 changes: 5 additions & 0 deletions src/channel/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Context {
const position: CR.Position = this.position.setPositionFromProgress(tutorial, progress)
return {progress, position}
}
public reset = () => {
this.tutorial.reset()
this.progress.reset()
this.position.reset()
}
}

export default Context
2 changes: 1 addition & 1 deletion src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Channel implements Channel {
// clear tutorial local storage
case 'TUTORIAL_CLEAR':
// clear current progress/position/tutorial
this.context = new Context(this.workspaceState)
this.context.reset()
return
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
Expand Down
15 changes: 10 additions & 5 deletions src/channel/state/Position.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import * as CR from 'typings'
import * as G from 'typings/graphql'

const defaultValue: CR.Position = {
levelId: '',
stageId: '',
stepId: '',
}

// position
class Position {
private value: CR.Position
constructor() {
this.value = {
levelId: '',
stageId: '',
stepId: '',
}
this.value = defaultValue
}
public get = () => {
return this.value
}
public set = (value: CR.Position) => {
this.value = value
}
public reset = () => {
this.value = defaultValue
}
// calculate the current position based on the saved progress
public setPositionFromProgress = (tutorial: G.Tutorial, progress: CR.Progress): CR.Position => {

Expand Down
8 changes: 6 additions & 2 deletions src/channel/state/Progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ class Progress {
}
public set = (value: CR.Progress) => {
this.value = value
if (this.storage) {
this.storage.set(value)
if (!this.storage) {
throw new Error('Tutorial storage not found')
}
this.storage.set(value)
return this.value
}
public reset = () => {
this.set(defaultValue)
}
public setStepComplete = (stepId: string): CR.Progress => {
const next = this.value
next.steps[stepId] = true
Expand Down
10 changes: 6 additions & 4 deletions src/channel/state/Tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class Tutorial {
this.value = value
})
}
public get = () => {
return this.value
}
public set = (value: G.Tutorial) => {
public get = () => this.value
public set = (value: G.Tutorial | null) => {
this.value = value
this.storage.set(value)
}
public reset = () => {
this.set(null)
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ReactWebView {
private channel: Channel

public constructor({extensionPath, workspaceState}: ReactWebViewProps) {
console.log(`extPath ${extensionPath}`)
this.extensionPath = extensionPath

// Create and show a new webview panel
Expand Down Expand Up @@ -73,7 +72,7 @@ class ReactWebView {
this.channel = new Channel({
workspaceState,
postMessage: (action: Action): Thenable<boolean> => {
console.log(`postMessage ${JSON.stringify(action)}`)
// console.log(`postMessage ${JSON.stringify(action)}`)
return this.panel.webview.postMessage(action)
}
})
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
})
}
},
clearStorage() {
clearStorage(): void {
channel.editorSend({type: 'TUTORIAL_CLEAR'})
}
}
2 changes: 1 addition & 1 deletion web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
},
NEW_TUTORIAL: {
target: 'SelectTutorial',
actions: ['clearStorage']
}
},
},
SelectTutorial: {
onEntry: ['clearStorage'],
id: 'start-new-tutorial',
on: {
TUTORIAL_START: {
Expand Down