File tree Expand file tree Collapse file tree 11 files changed +83
-32
lines changed
containers/Tutorial/StagePage Expand file tree Collapse file tree 11 files changed +83
-32
lines changed Original file line number Diff line number Diff line change 1
- // import * as CR from 'typings'
2
1
import * as G from 'typings/graphql'
3
- // import {TutorialModel} from '../services/tutorial'
4
- // import {gitLoadCommits, gitClear} from '../services/git'
5
-
6
- const solutionActions = 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 * as vscode from 'vscode'
3
+ import * as git from '../services/git'
4
+ import setupActions from './setupActions'
14
5
6
+ const solutionActions = async ( workspaceRoot : vscode . WorkspaceFolder , stepActions : G . StepActions ) : Promise < void > => {
7
+ await git . clear ( )
8
+ return setupActions ( workspaceRoot , stepActions )
15
9
}
16
10
17
11
export default solutionActions
Original file line number Diff line number Diff line change @@ -105,7 +105,9 @@ class Channel implements Channel {
105
105
return
106
106
// load solution step actions (git commits, commands, open files)
107
107
case 'SOLUTION_ACTIONS' :
108
- solutionActions ( action . payload )
108
+ await solutionActions ( this . workspaceRoot , action . payload )
109
+ // run test following solution to update position
110
+ vscode . commands . executeCommand ( 'coderoad.run_test' , action . payload )
109
111
return
110
112
111
113
default :
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ class Progress {
33
33
public set = ( value : CR . Progress ) => {
34
34
this . value = value
35
35
if ( ! this . storage ) {
36
- throw new Error ( 'Tutorial storage not found' )
36
+ return defaultValue
37
37
}
38
38
this . storage . set ( value )
39
39
return this . value
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ export type Stage = {
136
136
step ?: Maybe < Step > ,
137
137
steps : Array < Step > ,
138
138
setup ?: Maybe < StepActions > ,
139
- status : string
139
+ status : 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
140
140
} ;
141
141
142
142
@@ -151,8 +151,8 @@ export type Step = {
151
151
text : Scalars [ 'String' ] ,
152
152
setup : StepActions ,
153
153
solution : StepActions ,
154
- status : string
155
- } ;
154
+ status : 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
155
+ }
156
156
157
157
export type StepActions = {
158
158
__typename ?: 'StepActions' ,
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
import { ApolloProvider } from '@apollo/react-hooks'
3
3
4
+ import ErrorBoundary from './components/ErrorBoundary'
4
5
import client from './services/apollo'
5
6
import Routes from './Routes'
6
7
7
8
const App = ( ) => (
8
- < ApolloProvider client = { client } >
9
- < Routes />
10
- </ ApolloProvider >
9
+ < ErrorBoundary >
10
+ < ApolloProvider client = { client } >
11
+ < Routes />
12
+ </ ApolloProvider >
13
+ </ ErrorBoundary >
11
14
)
12
15
13
16
export default App
Original file line number Diff line number Diff line change
1
+ import * as React from 'react'
2
+
3
+ class ErrorBoundary extends React . Component {
4
+ public state = { hasError : false }
5
+
6
+ public componentDidCatch ( 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
+ public render ( ) {
15
+ if ( this . state . hasError ) {
16
+ // You can render any custom fallback UI
17
+ return < h1 > Something went wrong.</ h1 >
18
+ }
19
+ return this . props . children
20
+ }
21
+ }
22
+
23
+ export default ErrorBoundary
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
2
import Markdown from '../../../../../components/Markdown'
3
+ import { Button } from '@alifd/next'
3
4
4
5
const styles = {
5
6
// active: {
@@ -12,16 +13,29 @@ const styles = {
12
13
13
14
interface Props {
14
15
text ?: string | null
15
- hide : boolean
16
+ mode : 'INCOMPLETE' | 'ACTIVE' | 'COMPLETE'
17
+ onLoadSolution ( ) : void
16
18
}
17
19
18
- const StepDescription = ( { text, hide } : Props ) => {
19
- if ( hide ) {
20
+ const StepDescription = ( { text, mode, onLoadSolution } : Props ) => {
21
+ const [ loadedSolution , setLoadedSolution ] = React . useState ( )
22
+
23
+ const onClickHandler = ( ) => {
24
+ if ( ! loadedSolution ) {
25
+ setLoadedSolution ( true )
26
+ onLoadSolution ( )
27
+ }
28
+ }
29
+
30
+ if ( mode === 'INCOMPLETE' ) {
20
31
return null
21
32
}
33
+
34
+ const showLoadSolution = mode === 'ACTIVE' && ! loadedSolution
22
35
return (
23
36
< div style = { styles . card } >
24
37
< Markdown > { text || '' } </ Markdown >
38
+ { showLoadSolution && < Button onClick = { onClickHandler } > Load Solution</ Button > }
25
39
</ div >
26
40
)
27
41
}
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ const StageSummaryPageContainer = (props: PageProps) => {
33
33
} )
34
34
}
35
35
36
+ const onLoadSolution = ( ) : void => {
37
+ props . send ( { type : 'STEP_SOLUTION_LOAD' } )
38
+ }
39
+
36
40
stage . steps . forEach ( ( step : G . Step ) => {
37
41
if ( progress . steps [ step . id ] ) {
38
42
step . status = 'COMPLETE'
@@ -44,7 +48,7 @@ const StageSummaryPageContainer = (props: PageProps) => {
44
48
} )
45
49
stage . status = progress . stages [ position . stageId ] ? 'COMPLETE' : 'ACTIVE'
46
50
47
- return < Stage stage = { stage } onContinue = { onContinue } onSave = { onSave } />
51
+ return < Stage stage = { stage } onContinue = { onContinue } onSave = { onSave } onLoadSolution = { onLoadSolution } />
48
52
}
49
53
50
54
export default StageSummaryPageContainer
Original file line number Diff line number Diff line change @@ -97,6 +97,17 @@ export default {
97
97
} )
98
98
}
99
99
} ,
100
+ editorLoadSolution ( context : CR . MachineContext ) : void {
101
+ const step : 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
+ } ,
100
111
clearStorage ( ) : void {
101
112
channel . editorSend ( { type : 'TUTORIAL_CLEAR' } )
102
113
}
You can’t perform that action at this time.
0 commit comments