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

Commit7766d82

Browse files
committed
remove progress progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent4c8eb65 commit7766d82

File tree

29 files changed

+466
-546
lines changed

29 files changed

+466
-546
lines changed

‎src/actions/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export{defaultasonStartup}from'./onStartup'
2-
export{defaultasonTutorialConfig}from'./onTutorialConfig'
3-
export{defaultasonTutorialContinueConfig}from'./onTutorialContinueConfig'
2+
export{defaultasonTutorialConfigNew}from'./onTutorialConfigNew'
3+
export{defaultasonTutorialConfigContinue}from'./onTutorialConfigContinue'
44
export{defaultasonValidateSetup}from'./onValidateSetup'
55
export{defaultasonRunReset}from'./onRunReset'
66
export{defaultasonErrorPage}from'./onErrorPage'

‎src/actions/onStartup.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,26 @@ const onStartup = async (
4141
// no stored tutorial, must start new tutorial
4242
if(!tutorial||!tutorial.id){
4343
if(TUTORIAL_URL){
44-
//launch from a url env variable
44+
//NEW_FROM_URL
4545
try{
4646
consttutorialRes=awaitfetch(TUTORIAL_URL)
4747
consttutorial=awaittutorialRes.json()
4848
send({type:'START_TUTORIAL_FROM_URL',payload:{ tutorial}})
49+
return
4950
}catch(e){
51+
// on failure to load a tutorial url fallback to NEW
5052
console.log(`Failed to load tutorial from url${TUTORIAL_URL} with error "${e.message}"`)
5153
}
52-
}else{
53-
// launch from a selected tutorial
54-
send({type:'START_NEW_TUTORIAL',payload:{ env}})
5554
}
55+
// NEW
56+
send({type:'START_NEW_TUTORIAL',payload:{ env}})
5657
return
5758
}
5859

59-
// load continued tutorial position & progress
60-
const{ position, progress}=awaitcontext.setTutorial(workspaceState,tutorial)
61-
logger('CONTINUE STATE',position,progress)
62-
63-
if(progress.complete){
64-
// tutorial is already complete
65-
send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
66-
return
67-
}
60+
// CONTINUE_FROM_PROGRESS
61+
const{ position}=awaitcontext.onContinue(tutorial)
6862
// communicate to client the tutorial & stepProgress state
69-
send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial,progress,position}})
63+
send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, position}})
7064
}catch(e){
7165
consterror={
7266
type:'UnknownError',

‎src/actions/onTest.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import { COMMANDS } from '../commands'
55
importContextfrom'../services/context/context'
66

77
exportconstonTestPass=(action:T.Action,context:Context)=>{
8-
consttutorial=context.tutorial.get()
9-
if(!tutorial){
10-
thrownewError('Error with current tutorial. Tutorial may be missing an id.')
11-
}
12-
// update local storage stepProgress
13-
constprogress=context.progress.setStepComplete(tutorial,action.payload.position.stepId)
14-
context.position.setPositionFromProgress(tutorial,progress)
8+
context.position.set({ ...action.payload.position,complete:true})
159
git.saveCommit('Save progress')
1610
}
1711

‎src/actions/onTutorialContinueConfig.tsrenamed to‎src/actions/onTutorialConfigContinue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Context from '../services/context/context'
55
importtutorialConfigfrom'./utils/tutorialConfig'
66
import{COMMANDS}from'../commands'
77

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

29-
exportdefaultonTutorialContinueConfig
29+
exportdefaultonTutorialConfigContinue

‎src/actions/onTutorialConfig.tsrenamed to‎src/actions/onTutorialConfigNew.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { version, compareVersions } from '../services/dependencies'
88
importContextfrom'../services/context/context'
99
importtutorialConfigfrom'./utils/tutorialConfig'
1010

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

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

3939
// setup tutorial config (save watcher, test runner, etc)
40-
awaitcontext.setTutorial(workspaceState,data)
40+
awaitcontext.onNew(data)
4141

4242
// validate dependencies
4343
constdependencies=data.config.dependencies
@@ -118,4 +118,4 @@ const onTutorialConfig = async (action: T.Action, context: Context, workspaceSta
118118
}
119119
}
120120

121-
exportdefaultonTutorialConfig
121+
exportdefaultonTutorialConfigNew

‎src/channel.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ class Channel implements Channel {
4040
actions.onStartup(this.context,this.workspaceState,this.send)
4141
return
4242
// clear tutorial local storage
43-
case'TUTORIAL_CLEAR':
44-
// clear current progress/position/tutorial
45-
this.context.reset()
46-
return
4743
// configure test runner, language, git
4844
case'EDITOR_TUTORIAL_CONFIG':
49-
actions.onTutorialConfig(action,this.context,this.workspaceState,this.send)
45+
actions.onTutorialConfigNew(action,this.context,this.send)
5046
return
5147
case'EDITOR_TUTORIAL_CONTINUE_CONFIG':
52-
actions.onTutorialContinueConfig(action,this.context,this.send)
48+
actions.onTutorialConfigContinue(action,this.context,this.send)
5349
return
5450
case'EDITOR_VALIDATE_SETUP':
5551
actions.onValidateSetup(this.send)
@@ -69,9 +65,9 @@ class Channel implements Channel {
6965
// run test following solution to update position
7066
actions.onRunTest()
7167
return
72-
case'EDITOR_SYNC_PROGRESS':
68+
case'EDITOR_SYNC_POSITION':
7369
// update progress when a level is deemed complete in the client
74-
awaitthis.context.progress.syncProgress(action.payload.progress)
70+
awaitthis.context.position.set(action.payload.position)
7571
return
7672
case'EDITOR_OPEN_LOGS':
7773
actions.onOpenLogs(action)

‎src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Env = 'test' | 'local' | 'development' | 'production'
1111
exportconstNODE_ENV:Env=process.env.NODE_ENV||'development'
1212

1313
// toggle logging in development
14-
exportconstLOG=false
14+
exportconstLOG=true
1515

1616
// error logging tool
1717
exportconstINSTRUMENTATION_KEY='6ff37c76-72f3-48e3-a1b9-d5636f519b7b'

‎src/services/context/context.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
1-
import*asCRfrom'typings'
1+
import*asTfrom'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
44
importPositionfrom'./state/Position'
5-
importProgressfrom'./state/Progress'
65
importTutorialfrom'./state/Tutorial'
76

87
classContext{
98
publictutorial:Tutorial
109
publicposition:Position
11-
publicprogress:Progress
10+
privateworkspaceState:vscode.Memento
1211
constructor(workspaceState:vscode.Memento){
1312
// state held in one place
13+
this.workspaceState=workspaceState
1414
this.tutorial=newTutorial(workspaceState)
1515
this.position=newPosition()
16-
this.progress=newProgress()
1716
}
18-
publicsetTutorial=async(
19-
workspaceState:vscode.Memento,
20-
tutorial:TT.Tutorial,
21-
):Promise<{progress:CR.Progress;position:CR.Position}>=>{
17+
publiconNew=async(tutorial:TT.Tutorial):Promise<{position:T.Position}>=>{
2218
this.tutorial.set(tutorial)
23-
constprogress:CR.Progress=awaitthis.progress.setTutorial(workspaceState,tutorial)
24-
constposition:CR.Position=this.position.setPositionFromProgress(tutorial,progress)
25-
return{ progress, position}
19+
constposition:T.Position=awaitthis.position.initPosition(this.workspaceState,tutorial)
20+
return{ position}
2621
}
27-
publicreset=():void=>{
28-
this.tutorial.reset()
29-
this.progress.reset()
30-
this.position.reset()
22+
publiconContinue=async(tutorial:TT.Tutorial):Promise<{position:T.Position}>=>{
23+
constposition:T.Position=awaitthis.position.continuePosition(this.workspaceState,tutorial)
24+
return{ position}
3125
}
3226
}
3327

‎src/services/context/state/Position.ts

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,54 @@
1-
import*asCRfrom'typings'
1+
import*asvscodefrom'vscode'
2+
import*asTfrom'typings'
23
import*asTTfrom'typings/tutorial'
4+
importStoragefrom'../../storage'
35

4-
constdefaultValue:CR.Position={
6+
constdefaultValue:T.Position={
57
levelId:'',
68
stepId:null,
9+
complete:false,
710
}
811

912
// position
1013
classPosition{
11-
privatevalue:CR.Position
14+
privatevalue:T.Position
15+
privatestorage:Storage<T.Position>|undefined
1216
constructor(){
1317
this.value=defaultValue
1418
}
19+
setTutorial(workspaceState:vscode.Memento,tutorial:TT.Tutorial){
20+
this.storage=newStorage<T.Position>({
21+
key:`coderoad:position:${tutorial.id}:${tutorial.version}`,
22+
storage:workspaceState,
23+
defaultValue,
24+
})
25+
}
26+
asyncinitPosition(workspaceState:vscode.Memento,tutorial:TT.Tutorial):Promise<T.Position>{
27+
// set value from storage
28+
this.setTutorial(workspaceState,tutorial)
29+
// find first level & step id
30+
letinitLevel=tutorial.levels.length ?tutorial.levels[0] :null
31+
returnthis.set({
32+
levelId:initLevel?.id||'',
33+
stepId:initLevel?.steps.length ?initLevel.steps[0].id :null,
34+
complete:false,
35+
})
36+
}
37+
asynccontinuePosition(workspaceState:vscode.Memento,tutorial:TT.Tutorial):Promise<T.Position>{
38+
this.setTutorial(workspaceState,tutorial)
39+
letposition:T.Position=(awaitthis.storage?.get())||defaultValue
40+
returnthis.set(position)
41+
}
1542
publicget=()=>{
1643
returnthis.value
1744
}
18-
publicset=(value:CR.Position)=>{
45+
publicset=(value:T.Position)=>{
1946
this.value=value
47+
this.storage?.set(value)
48+
returnthis.value
2049
}
2150
publicreset=()=>{
22-
this.value=defaultValue
23-
}
24-
// calculate the current position based on the saved progress
25-
publicsetPositionFromProgress=(tutorial:TT.Tutorial,progress:CR.Progress):CR.Position=>{
26-
// tutorial already completed
27-
// TODO handle start again?
28-
if(progress.complete){
29-
returnthis.value
30-
}
31-
32-
if(!tutorial||!tutorial.levels){
33-
thrownewError('Error setting position from progress')
34-
}
35-
36-
// get level
37-
const{ levels}=tutorial
38-
constlastLevelIndex:number|undefined=levels.findIndex((l:TT.Level)=>!progress.levels[l.id])
39-
if(lastLevelIndex>=levels.length){
40-
thrownewError('Error setting progress level')
41-
}
42-
43-
// get step
44-
constcurrentLevel:TT.Level=levels[lastLevelIndex]
45-
if(!currentLevel){
46-
// tutorial complete but not reached completed view
47-
constfinalLevel=levels[levels.length-1]
48-
return{
49-
levelId:finalLevel.id,
50-
stepId:finalLevel.steps.length ?finalLevel.steps[finalLevel.steps.length-1].id :null,
51-
complete:true,
52-
}
53-
}
54-
letcurrentStepId:string|null
55-
if(!currentLevel.steps.length){
56-
// no steps available for level
57-
currentStepId=null
58-
}else{
59-
// find current step id
60-
const{ steps}=currentLevel
61-
constlastStepIndex:number|undefined=steps.findIndex((s:TT.Step)=>!progress.steps[s.id])
62-
if(lastStepIndex>=steps.length){
63-
thrownewError('Error setting progress step')
64-
}
65-
// handle position when last step is complete but "continue" not yet selected
66-
constadjustedLastStepIndex=lastStepIndex===-1 ?steps.length-1 :lastStepIndex
67-
currentStepId=steps[adjustedLastStepIndex].id
68-
}
69-
70-
this.value={
71-
levelId:currentLevel.id,
72-
stepId:currentStepId,
73-
}
74-
75-
returnthis.value
51+
returnthis.set(defaultValue)
7652
}
7753
}
7854

‎src/services/context/state/Progress.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

‎src/services/reset/lastHash.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import getLastCommitHash from './lastHash'
44

55
describe('lastHash',()=>{
66
it('should grab the last passing hash from a step',()=>{
7-
constposition:T.Position={levelId:'1',stepId:'1.2'}
7+
constposition:T.Position={levelId:'1',stepId:'1.2',complete:false}
88
//@ts-ignore
99
consttutorial:TT.Tutorial={
1010
levels:[
@@ -32,7 +32,7 @@ describe('lastHash', () => {
3232
expect(result).toBe('abcdef2')
3333
})
3434
it('should grab the last passing hash from a step with several commits',()=>{
35-
constposition:T.Position={levelId:'1',stepId:'1.2'}
35+
constposition:T.Position={levelId:'1',stepId:'1.2',complete:false}
3636
//@ts-ignore
3737
consttutorial:TT.Tutorial={
3838
levels:[
@@ -60,7 +60,7 @@ describe('lastHash', () => {
6060
expect(result).toBe('abcdef3')
6161
})
6262
it('should grab the last passing hash when level has no steps',()=>{
63-
constposition:T.Position={levelId:'1',stepId:null}
63+
constposition:T.Position={levelId:'1',stepId:null,complete:false}
6464
//@ts-ignore
6565
consttutorial:TT.Tutorial={
6666
config:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp