Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/remove progress#414

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 14 commits intomasterfromfeature/remove-progress
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
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
5 changes: 5 additions & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -236,3 +236,8 @@ Adds a review page for viewing tutorial content. The review page should be espec
- Launch from URL fixes
- Move styles into a central theme
- Prevent multiple versions of CodeRoad from launching

### [0.13.0]

- Significant internal refactor to remove recording progress
- Admin mode to allow creators to jump between tutorial levels/steps during development
4 changes: 2 additions & 2 deletionssrc/actions/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
export{defaultasonStartup}from'./onStartup'
export{defaultasonTutorialConfig}from'./onTutorialConfig'
export{defaultasonTutorialContinueConfig}from'./onTutorialContinueConfig'
export{defaultasonTutorialConfigNew}from'./onTutorialConfigNew'
export{defaultasonTutorialConfigContinue}from'./onTutorialConfigContinue'
export{defaultasonValidateSetup}from'./onValidateSetup'
export{defaultasonRunReset}from'./onRunReset'
export{defaultasonErrorPage}from'./onErrorPage'
Expand Down
22 changes: 8 additions & 14 deletionssrc/actions/onStartup.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,32 +41,26 @@ const onStartup = async (
// no stored tutorial, must start new tutorial
if(!tutorial||!tutorial.id){
if(TUTORIAL_URL){
//launch from a url env variable
//NEW_FROM_URL
try{
consttutorialRes=awaitfetch(TUTORIAL_URL)
consttutorial=awaittutorialRes.json()
send({type:'START_TUTORIAL_FROM_URL',payload:{ tutorial}})
return
}catch(e){
// on failure to load a tutorial url fallback to NEW
console.log(`Failed to load tutorial from url${TUTORIAL_URL} with error "${e.message}"`)
}
}else{
// launch from a selected tutorial
send({type:'START_NEW_TUTORIAL',payload:{ env}})
}
// NEW
send({type:'START_NEW_TUTORIAL',payload:{ env}})
return
}

// load continued tutorial position & progress
const{ position, progress}=awaitcontext.setTutorial(workspaceState,tutorial)
logger('CONTINUE STATE',position,progress)

if(progress.complete){
// tutorial is already complete
send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
return
}
// CONTINUE_FROM_PROGRESS
const{ position}=awaitcontext.onContinue(tutorial)
// communicate to client the tutorial & stepProgress state
send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial,progress,position}})
send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, position}})
}catch(e){
consterror={
type:'UnknownError',
Expand Down
8 changes: 1 addition & 7 deletionssrc/actions/onTest.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,13 +5,7 @@ import { COMMANDS } from '../commands'
importContextfrom'../services/context/context'

exportconstonTestPass=(action:T.Action,context:Context)=>{
consttutorial=context.tutorial.get()
if(!tutorial){
thrownewError('Error with current tutorial. Tutorial may be missing an id.')
}
// update local storage stepProgress
constprogress=context.progress.setStepComplete(tutorial,action.payload.position.stepId)
context.position.setPositionFromProgress(tutorial,progress)
context.position.set({ ...action.payload.position,complete:true})
git.saveCommit('Save progress')
}

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import Context from '../services/context/context'
importtutorialConfigfrom'./utils/tutorialConfig'
import{COMMANDS}from'../commands'

constonTutorialContinueConfig=async(action:T.Action,context:Context,send:any)=>{
constonTutorialConfigContinue=async(action:T.Action,context:Context,send:any)=>{
try{
consttutorialContinue:TT.Tutorial|null=context.tutorial.get()
if(!tutorialContinue){
Expand All@@ -26,4 +26,4 @@ const onTutorialContinueConfig = async (action: T.Action, context: Context, send
}
}

exportdefaultonTutorialContinueConfig
exportdefaultonTutorialConfigContinue
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ import { version, compareVersions } from '../services/dependencies'
importContextfrom'../services/context/context'
importtutorialConfigfrom'./utils/tutorialConfig'

constonTutorialConfig=async(action:T.Action,context:Context,workspaceState:vscode.Memento,send:any)=>{
constonTutorialConfigNew=async(action:T.Action,context:Context,send:any)=>{
try{
constdata:TT.Tutorial=action.payload.tutorial

Expand DownExpand Up@@ -37,7 +37,7 @@ const onTutorialConfig = async (action: T.Action, context: Context, workspaceSta
}

// setup tutorial config (save watcher, test runner, etc)
awaitcontext.setTutorial(workspaceState,data)
awaitcontext.onNew(data)

// validate dependencies
constdependencies=data.config.dependencies
Expand DownExpand Up@@ -118,4 +118,4 @@ const onTutorialConfig = async (action: T.Action, context: Context, workspaceSta
}
}

exportdefaultonTutorialConfig
exportdefaultonTutorialConfigNew
12 changes: 4 additions & 8 deletionssrc/channel.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,16 +40,12 @@ class Channel implements Channel {
actions.onStartup(this.context, this.workspaceState, this.send)
return
// clear tutorial local storage
case 'TUTORIAL_CLEAR':
// clear current progress/position/tutorial
this.context.reset()
return
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
actions.onTutorialConfig(action, this.context, this.workspaceState, this.send)
actions.onTutorialConfigNew(action, this.context, this.send)
return
case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
actions.onTutorialContinueConfig(action, this.context, this.send)
actions.onTutorialConfigContinue(action, this.context, this.send)
return
case 'EDITOR_VALIDATE_SETUP':
actions.onValidateSetup(this.send)
Expand All@@ -69,9 +65,9 @@ class Channel implements Channel {
// run test following solution to update position
actions.onRunTest()
return
case 'EDITOR_SYNC_PROGRESS':
case 'EDITOR_SYNC_POSITION':
// update progress when a level is deemed complete in the client
await this.context.progress.syncProgress(action.payload.progress)
await this.context.position.set(action.payload.position)
return
case 'EDITOR_OPEN_LOGS':
actions.onOpenLogs(action)
Expand Down
9 changes: 1 addition & 8 deletionssrc/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
onSuccess: (position: T.Position) => {
logger('test pass position', position)
// send test pass message back to client
webview.send({ type: 'TEST_PASS', payload: { position } })
webview.send({ type: 'TEST_PASS', payload: { position: { ...position, complete: true } } })
},
onFail: (position: T.Position, failSummary: T.TestFail): void => {
// send test fail message back to client with failure message
Expand DownExpand Up@@ -82,13 +82,6 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
subtasks,
callbacks,
}: { subtasks?: boolean; callbacks?: { onSuccess: () => void } } = {}) => {
logger('run test current', currentPosition)
// use stepId from client, or last set stepId
// const position: T.Position = {
// ...current,
// stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
// }
logger('currentPosition', currentPosition)
testRunner({ position: currentPosition, onSuccess: callbacks?.onSuccess, subtasks })
},
[COMMANDS.ENTER]: () => {
Expand Down
24 changes: 9 additions & 15 deletionssrc/services/context/context.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
import*asCRfrom'typings'
import*asTfrom'typings'
import*asTTfrom'typings/tutorial'
import*asvscodefrom'vscode'
importPositionfrom'./state/Position'
importProgressfrom'./state/Progress'
importTutorialfrom'./state/Tutorial'

classContext{
publictutorial:Tutorial
publicposition:Position
publicprogress:Progress
privateworkspaceState:vscode.Memento
constructor(workspaceState:vscode.Memento){
// state held in one place
this.workspaceState=workspaceState
this.tutorial=newTutorial(workspaceState)
this.position=newPosition()
this.progress=newProgress()
}
publicsetTutorial=async(
workspaceState:vscode.Memento,
tutorial:TT.Tutorial,
):Promise<{progress:CR.Progress;position:CR.Position}>=>{
publiconNew=async(tutorial:TT.Tutorial):Promise<{position:T.Position}>=>{
this.tutorial.set(tutorial)
constprogress:CR.Progress=awaitthis.progress.setTutorial(workspaceState,tutorial)
constposition:CR.Position=this.position.setPositionFromProgress(tutorial,progress)
return{ progress, position}
constposition:T.Position=awaitthis.position.initPosition(this.workspaceState,tutorial)
return{ position}
}
publicreset=():void=>{
this.tutorial.reset()
this.progress.reset()
this.position.reset()
publiconContinue=async(tutorial:TT.Tutorial):Promise<{position:T.Position}>=>{
constposition:T.Position=awaitthis.position.continuePosition(this.workspaceState,tutorial)
return{ position}
}
}

Expand Down
92 changes: 34 additions & 58 deletionssrc/services/context/state/Position.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,54 @@
import*asCRfrom'typings'
import*asvscodefrom'vscode'
import*asTfrom'typings'
import*asTTfrom'typings/tutorial'
importStoragefrom'../../storage'

constdefaultValue:CR.Position={
constdefaultValue:T.Position={
levelId:'',
stepId:null,
complete:false,
}

// position
classPosition{
privatevalue:CR.Position
privatevalue:T.Position
privatestorage:Storage<T.Position>|undefined
constructor(){
this.value=defaultValue
}
setTutorial(workspaceState:vscode.Memento,tutorial:TT.Tutorial){
this.storage=newStorage<T.Position>({
key:`coderoad:position:${tutorial.id}:${tutorial.version}`,
storage:workspaceState,
defaultValue,
})
}
asyncinitPosition(workspaceState:vscode.Memento,tutorial:TT.Tutorial):Promise<T.Position>{
// set value from storage
this.setTutorial(workspaceState,tutorial)
// find first level & step id
letinitLevel=tutorial.levels.length ?tutorial.levels[0] :null
returnthis.set({
levelId:initLevel?.id||'',
stepId:initLevel?.steps.length ?initLevel.steps[0].id :null,
complete:false,
})
}
asynccontinuePosition(workspaceState:vscode.Memento,tutorial:TT.Tutorial):Promise<T.Position>{
this.setTutorial(workspaceState,tutorial)
letposition:T.Position=(awaitthis.storage?.get())||defaultValue
returnthis.set(position)
}
publicget=()=>{
returnthis.value
}
publicset=(value:CR.Position)=>{
publicset=(value:T.Position)=>{
this.value=value
this.storage?.set(value)
returnthis.value
}
publicreset=()=>{
this.value=defaultValue
}
// calculate the current position based on the saved progress
publicsetPositionFromProgress=(tutorial:TT.Tutorial,progress:CR.Progress):CR.Position=>{
// tutorial already completed
// TODO handle start again?
if(progress.complete){
returnthis.value
}

if(!tutorial||!tutorial.levels){
thrownewError('Error setting position from progress')
}

// get level
const{ levels}=tutorial
constlastLevelIndex:number|undefined=levels.findIndex((l:TT.Level)=>!progress.levels[l.id])
if(lastLevelIndex>=levels.length){
thrownewError('Error setting progress level')
}

// get step
constcurrentLevel:TT.Level=levels[lastLevelIndex]
if(!currentLevel){
// tutorial complete but not reached completed view
constfinalLevel=levels[levels.length-1]
return{
levelId:finalLevel.id,
stepId:finalLevel.steps.length ?finalLevel.steps[finalLevel.steps.length-1].id :null,
complete:true,
}
}
letcurrentStepId:string|null
if(!currentLevel.steps.length){
// no steps available for level
currentStepId=null
}else{
// find current step id
const{ steps}=currentLevel
constlastStepIndex:number|undefined=steps.findIndex((s:TT.Step)=>!progress.steps[s.id])
if(lastStepIndex>=steps.length){
thrownewError('Error setting progress step')
}
// handle position when last step is complete but "continue" not yet selected
constadjustedLastStepIndex=lastStepIndex===-1 ?steps.length-1 :lastStepIndex
currentStepId=steps[adjustedLastStepIndex].id
}

this.value={
levelId:currentLevel.id,
stepId:currentStepId,
}

returnthis.value
returnthis.set(defaultValue)
}
}

Expand Down
70 changes: 0 additions & 70 deletionssrc/services/context/state/Progress.ts
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp