1
1
import * as React from 'react'
2
- import { ApolloProvider } from '@apollo/react-hooks'
2
+ import { ApolloProvider , useMutation } from '@apollo/react-hooks'
3
3
import * as CR from 'typings'
4
4
5
5
import client from './services/apollo'
6
+ import { SET_STATUS } from './services/apollo/mutations'
6
7
import Debugger from './components/Debugger'
7
8
import Routes from './Routes'
8
- import DataContext , { initialData , initialState } from './utils/DataContext'
9
9
import { send } from './utils/vscode'
10
10
11
11
interface ReceivedEvent {
12
12
data : CR . Action
13
13
}
14
14
15
15
const App = ( ) => {
16
+ const initialState = { SelectTutorial : 'Initial ' }
17
+
18
+ // set state machine state
16
19
const [ state , setState ] = React . useState ( initialState )
17
- const [ data , setData ] : [ CR . MachineContext , ( data : CR . MachineContext ) => void ] = React . useState ( initialData )
20
+
21
+ // update level/stage/step status based on user progress & position
22
+ // TODO: model server more effeciently
23
+ const [ setStatus ] = useMutation ( SET_STATUS )
18
24
19
25
// update state based on response from editor
20
26
const handleEvent = ( event : ReceivedEvent ) : void => {
21
27
const message = event . data
22
28
// messages from core
29
+ const { progress, position } = message . payload . data
30
+
23
31
if ( message . type === 'SET_STATE' ) {
32
+ // SET_STATE - set state machine state
24
33
setState ( message . payload . state )
25
- setData ( message . payload . data )
34
+
35
+ setStatus ( { variables : { progress, position } } )
26
36
} else if ( message . type === 'SET_DATA' ) {
27
- setData ( message . payload . data )
37
+ // SET_DATA - set state machine context
38
+ setStatus ( { variables : { progress, position } } )
28
39
}
29
40
}
30
41
@@ -44,20 +55,15 @@ const App = () => {
44
55
45
56
const value = {
46
57
state,
47
- position : data . position ,
48
- data : data . data ,
49
- progress : data . progress ,
50
58
}
51
59
52
60
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
53
61
return (
54
62
< ApolloProvider client = { client } >
55
- < DataContext . Provider value = { value } >
56
- < div >
57
- { process . env . REACT_APP_DEBUG && < Debugger value = { value } /> }
58
- < Routes state = { state } />
59
- </ div >
60
- </ DataContext . Provider >
63
+ < div >
64
+ { process . env . REACT_APP_DEBUG && < Debugger value = { value } /> }
65
+ < Routes state = { state } />
66
+ </ div >
61
67
</ ApolloProvider >
62
68
)
63
69
}
0 commit comments