Skip to content

Continue progress #32

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 27 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
17a71b7
setup storage on server
ShMcK Sep 9, 2019
1b99222
continue tutorial progress
ShMcK Sep 9, 2019
90e5e97
store tutorial id/version on server
ShMcK Sep 9, 2019
e49165c
manage storage in editor Channel
ShMcK Sep 14, 2019
0f992bf
setup storage in editor channel
ShMcK Sep 15, 2019
f174afa
load progress on server and send to client
ShMcK Sep 15, 2019
ecac58b
add continue option to start new
ShMcK Sep 15, 2019
33d854c
load stage (not 100%)
ShMcK Sep 15, 2019
a54f1d5
save commit on successful test
ShMcK Sep 15, 2019
8bea508
setup editor position & progress state
ShMcK Sep 15, 2019
83820ab
cleanup deps
ShMcK Sep 18, 2019
04d3eca
update deps
ShMcK Sep 21, 2019
b1eb6b1
refactor context
ShMcK Sep 21, 2019
d1d5384
setup position/progress/tutorial context
ShMcK Sep 21, 2019
1a9ccf9
refactor setupActions
ShMcK Sep 21, 2019
6217ea6
align channel with context
ShMcK Sep 21, 2019
e7b084d
fix build process
ShMcK Sep 21, 2019
229c6b8
parse webview from jsdom
ShMcK Sep 21, 2019
bab2e54
refactor webview render
ShMcK Sep 21, 2019
7bada36
fix webview after webpack build breakage
ShMcK Sep 22, 2019
22451c7
fix react web view for latest webpack
ShMcK Sep 22, 2019
6f8bee2
add extensive comments to react webview
ShMcK Sep 22, 2019
13a4499
clear up CSP issue with GQL
ShMcK Sep 22, 2019
ccd088b
fix loading tutorial position
ShMcK Sep 22, 2019
30dd21c
fix issues with tutorial init
ShMcK Sep 23, 2019
14d4f56
setup editor sync progress (uninitiated)
ShMcK Sep 23, 2019
4bb125d
clear tutorial on new
ShMcK Sep 23, 2019
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
Prev Previous commit
Next Next commit
align channel with context
  • Loading branch information
ShMcK committed Sep 21, 2019
commit 6217ea61715240407b8a7ed8a9927d1f8b19a89b
181 changes: 0 additions & 181 deletions src/Channel.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/channel/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Context {
this.position = new Position()
this.progress = new Progress()
}
setTutorial(tutorial: G.Tutorial, workspaceState: vscode.Memento) {
setTutorial(workspaceState: vscode.Memento, tutorial: G.Tutorial) {
this.tutorial.set(tutorial)
this.progress.setTutorial(workspaceState, tutorial)
}
Expand Down
116 changes: 116 additions & 0 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import * as CR from 'typings'
import * as G from 'typings/graphql'
import * as vscode from 'vscode'

import Context from './context'
import tutorialConfig from '../actions/tutorialConfig'
import setupActions from '../actions/setupActions'
import solutionActions from '../actions/solutionActions'
import saveCommit from '../actions/saveCommit'


interface Channel {
receive(action: CR.Action): Promise<void>
send(action: CR.Action): Promise<void>
}

interface ChannelProps {
postMessage: (action: CR.Action) => Thenable<boolean>
workspaceState: vscode.Memento
}


class Channel implements Channel {
private postMessage: (action: CR.Action) => Thenable<boolean>
private workspaceState: vscode.Memento
private context: Context
constructor({postMessage, workspaceState}: ChannelProps) {
// workspaceState used for local storage
this.workspaceState = workspaceState
this.postMessage = postMessage
this.context = new Context(workspaceState)
}

// receive from webview
public receive = async (action: CR.Action) => {
const actionType: string = typeof action === 'string' ? action : action.type
console.log('RECEIVED:', actionType)
switch (actionType) {
// continue from tutorial from local storage
case 'EDITOR_TUTORIAL_LOAD':
const tutorial: G.Tutorial | null = this.context.tutorial.get()

// new tutorial
if (!tutorial || !tutorial.id || !tutorial.version) {
this.send({type: 'NEW_TUTORIAL'})
return
}

// set tutorial
const progress: CR.Progress = await this.context.progress.setTutorial(this.workspaceState, tutorial)

console.log('looking at stored')
console.log(JSON.stringify(tutorial))
console.log(JSON.stringify(progress))

if (progress.complete) {
// tutorial is already complete
this.send({type: 'NEW_TUTORIAL'})
return
}

// communicate to client the tutorial & stepProgress state
this.send({type: 'CONTINUE_TUTORIAL', payload: {tutorial, progress, position}})

return
// clear tutorial local storage
case 'TUTORIAL_CLEAR':
// clear current progress/position/tutorial
this.context = new Context(this.workspaceState)
return
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
const tutorialData = action.payload.tutorial
console.log('tutorialConfig', JSON.stringify(tutorialData))
this.context.setTutorial(this.workspaceState, tutorialData)
tutorialConfig(tutorialData)
return
// run unit tests on step
case 'TEST_RUN':
vscode.commands.executeCommand('coderoad.run_test', action.payload)
return
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
vscode.commands.executeCommand('coderoad.set_current_step', action.payload)
setupActions(action.payload)
return
// load solution step actions (git commits, commands, open files)
case 'SOLUTION_ACTIONS':
solutionActions(action.payload)
return

default:
console.log(`No match for action type: ${actionType}`)
return
}
}
// send to webview
public send = async (action: CR.Action) => {

switch (action.type) {
case 'TEST_PASS':
// update local storage stepProgress
this.context.progress.setStepComplete(action.payload.stepId)
saveCommit()
}

const success = await this.postMessage(action)
if (!success) {
throw new Error(`Message post failure: ${JSON.stringify(action)}`)
}
}

}

export default Channel

12 changes: 8 additions & 4 deletions src/channel/state/Progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ class Progress {
constructor() {
this.value = defaultValue
}
public setTutorial = (workspaceState: vscode.Memento, tutorial: G.Tutorial) => {
public setTutorial = async (workspaceState: vscode.Memento, tutorial: G.Tutorial): Promise<CR.Progress> => {
this.storage = new Storage<CR.Progress>({
key: `coderoad:progress:${tutorial.id}:${tutorial.version}`,
storage: workspaceState,
defaultValue,
})// set value from storage
this.storage.get().then((value: CR.Progress) => {
this.value = value
})
this.value = await this.storage.get()
return this.value
}
public get = () => {
return this.value
Expand All @@ -37,6 +36,11 @@ class Progress {
this.storage.set(value)
}
}
public setStepComplete = (stepId: string) => {
const next = this.value
next.steps[stepId] = true
this.set(next)
}
}

export default Progress