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

Commitd76dcdb

Browse files
authored
Merge pull request#38 from ShMcK/feature/solution-actions
Feature/solution actions
2 parents6b14921 +6bf73c9 commitd76dcdb

File tree

11 files changed

+83
-32
lines changed

11 files changed

+83
-32
lines changed

‎src/actions/solutionActions.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
// import * as CR from 'typings'
21
import*asGfrom'typings/graphql'
3-
// import {TutorialModel} from '../services/tutorial'
4-
// import {gitLoadCommits, gitClear} from '../services/git'
5-
6-
constsolutionActions=async(stepActions:G.StepActions):Promise<void>=>{
7-
// TODO: should load same as commits
8-
9-
// const step: G.Step = tutorialModel.step()
10-
// const solution = step.solution
11-
12-
// await gitClear()
13-
// await gitLoadCommits(solution, dispatch)
2+
import*asvscodefrom'vscode'
3+
import*asgitfrom'../services/git'
4+
importsetupActionsfrom'./setupActions'
145

6+
constsolutionActions=async(workspaceRoot:vscode.WorkspaceFolder,stepActions:G.StepActions):Promise<void>=>{
7+
awaitgit.clear()
8+
returnsetupActions(workspaceRoot,stepActions)
159
}
1610

1711
exportdefaultsolutionActions

‎src/channel/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ class Channel implements Channel {
105105
return
106106
// load solution step actions (git commits, commands, open files)
107107
case'SOLUTION_ACTIONS':
108-
solutionActions(action.payload)
108+
awaitsolutionActions(this.workspaceRoot,action.payload)
109+
// run test following solution to update position
110+
vscode.commands.executeCommand('coderoad.run_test',action.payload)
109111
return
110112

111113
default:

‎src/channel/state/Progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Progress {
3333
publicset=(value:CR.Progress)=>{
3434
this.value=value
3535
if(!this.storage){
36-
thrownewError('Tutorial storage not found')
36+
returndefaultValue
3737
}
3838
this.storage.set(value)
3939
returnthis.value

‎typings/graphql.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export type Stage = {
136136
step?:Maybe<Step>,
137137
steps:Array<Step>,
138138
setup?:Maybe<StepActions>,
139-
status:string
139+
status:'ACTIVE'|'COMPLETE'|'INCOMPLETE'
140140
};
141141

142142

@@ -151,8 +151,8 @@ export type Step = {
151151
text:Scalars['String'],
152152
setup:StepActions,
153153
solution:StepActions,
154-
status:string
155-
};
154+
status:'ACTIVE'|'COMPLETE'|'INCOMPLETE'
155+
}
156156

157157
exporttypeStepActions={
158158
__typename?:'StepActions',

‎web-app/src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import*asReactfrom'react'
22
import{ApolloProvider}from'@apollo/react-hooks'
33

4+
importErrorBoundaryfrom'./components/ErrorBoundary'
45
importclientfrom'./services/apollo'
56
importRoutesfrom'./Routes'
67

78
constApp=()=>(
8-
<ApolloProviderclient={client}>
9-
<Routes/>
10-
</ApolloProvider>
9+
<ErrorBoundary>
10+
<ApolloProviderclient={client}>
11+
<Routes/>
12+
</ApolloProvider>
13+
</ErrorBoundary>
1114
)
1215

1316
exportdefaultApp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import*asReactfrom'react'
2+
3+
classErrorBoundaryextendsReact.Component{
4+
publicstate={hasError:false}
5+
6+
publiccomponentDidCatch(error:Error,info:any){
7+
// Display fallback UI
8+
this.setState({hasError:true})
9+
// You can also log the error to an error reporting service
10+
console.error(error)
11+
console.log(info)
12+
}
13+
14+
publicrender(){
15+
if(this.state.hasError){
16+
// You can render any custom fallback UI
17+
return<h1>Something went wrong.</h1>
18+
}
19+
returnthis.props.children
20+
}
21+
}
22+
23+
exportdefaultErrorBoundary

‎web-app/src/containers/Tutorial/StagePage/Stage/StepDescription/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import*asReactfrom'react'
22
importMarkdownfrom'../../../../../components/Markdown'
3+
import{Button}from'@alifd/next'
34

45
conststyles={
56
// active: {
@@ -12,16 +13,29 @@ const styles = {
1213

1314
interfaceProps{
1415
text?:string|null
15-
hide:boolean
16+
mode:'INCOMPLETE'|'ACTIVE'|'COMPLETE'
17+
onLoadSolution():void
1618
}
1719

18-
constStepDescription=({ text, hide}:Props)=>{
19-
if(hide){
20+
constStepDescription=({ text, mode, onLoadSolution}:Props)=>{
21+
const[loadedSolution,setLoadedSolution]=React.useState()
22+
23+
constonClickHandler=()=>{
24+
if(!loadedSolution){
25+
setLoadedSolution(true)
26+
onLoadSolution()
27+
}
28+
}
29+
30+
if(mode==='INCOMPLETE'){
2031
returnnull
2132
}
33+
34+
constshowLoadSolution=mode==='ACTIVE'&&!loadedSolution
2235
return(
2336
<divstyle={styles.card}>
2437
<Markdown>{text||''}</Markdown>
38+
{showLoadSolution&&<ButtononClick={onClickHandler}>Load Solution</Button>}
2539
</div>
2640
)
2741
}

‎web-app/src/containers/Tutorial/StagePage/Stage/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const styles = {
2424

2525
interfaceProps{
2626
stage:T.Stage
27-
onContinue():void
28-
onSave():void
27+
onContinue():void
28+
onSave():void
29+
onLoadSolution():void
2930
}
3031

31-
constStage=({ stage, onContinue, onSave}:Props)=>{
32+
constStage=({ stage, onContinue, onSave, onLoadSolution}:Props)=>{
3233
if(!stage.steps){
3334
thrownewError('No Stage steps found')
3435
}
@@ -50,12 +51,11 @@ const Stage = ({ stage, onContinue, onSave }: Props) => {
5051
if(!step){
5152
returnnull
5253
}
53-
consthide=step.status==='INCOMPLETE'
5454
return(
5555
<Step.Item
5656
key={step.id}
5757
title={step.title||`Step${index+1}`}
58-
content={<StepDescriptiontext={step.text}hide={hide}/>}
58+
content={<StepDescriptiontext={step.text}mode={step.status}onLoadSolution={onLoadSolution}/>}
5959
/>
6060
)
6161
})}
@@ -67,10 +67,10 @@ const Stage = ({ stage, onContinue, onSave }: Props) => {
6767
<ButtononClick={onContinue}>Continue</Button>
6868
</div>
6969
) :(
70-
<divstyle={styles.options}>
70+
<divstyle={styles.options}>
7171
<ButtononClick={onSave}>Save</Button>
7272
</div>
73-
)}
73+
)}
7474
</div>
7575
)
7676
}

‎web-app/src/containers/Tutorial/StagePage/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const StageSummaryPageContainer = (props: PageProps) => {
3333
})
3434
}
3535

36+
constonLoadSolution=():void=>{
37+
props.send({type:'STEP_SOLUTION_LOAD'})
38+
}
39+
3640
stage.steps.forEach((step:G.Step)=>{
3741
if(progress.steps[step.id]){
3842
step.status='COMPLETE'
@@ -44,7 +48,7 @@ const StageSummaryPageContainer = (props: PageProps) => {
4448
})
4549
stage.status=progress.stages[position.stageId] ?'COMPLETE' :'ACTIVE'
4650

47-
return<Stagestage={stage}onContinue={onContinue}onSave={onSave}/>
51+
return<Stagestage={stage}onContinue={onContinue}onSave={onSave}onLoadSolution={onLoadSolution}/>
4852
}
4953

5054
exportdefaultStageSummaryPageContainer

‎web-app/src/services/state/actions/editor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ export default {
9797
})
9898
}
9999
},
100+
editorLoadSolution(context:CR.MachineContext):void{
101+
conststep:G.Step=selectors.currentStep(context)
102+
// tell editor to load solution commit
103+
channel.editorSend({
104+
type:'SOLUTION_ACTIONS',
105+
payload:{
106+
stepId:step.id,
107+
...step.solution,
108+
}
109+
})
110+
},
100111
clearStorage():void{
101112
channel.editorSend({type:'TUTORIAL_CLEAR'})
102113
}

‎web-app/src/services/state/machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
113113
on:{
114114
TEST_RUN:'TestRunning',
115115
STEP_SOLUTION_LOAD:{
116-
actions:['callSolution'],
116+
actions:['editorLoadSolution'],
117117
},
118118
},
119119
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp