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

Commit8655db2

Browse files
authored
Merge pull request#40 from ShMcK/feature/github-oath
load machineId, sessionId on client from editor
2 parents9b391b0 +df20059 commit8655db2

File tree

10 files changed

+77
-17
lines changed

10 files changed

+77
-17
lines changed

‎src/channel/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ class Channel implements Channel {
4141

4242
// console.log('EDITOR RECEIVED:', actionType)
4343
switch(actionType){
44+
case'ENV_GET':
45+
this.send({
46+
type:'ENV_LOAD',
47+
payload:{
48+
env:{
49+
machineId:vscode.env.machineId,
50+
sessionId:vscode.env.sessionId,
51+
}
52+
}
53+
})
54+
return
4455
// continue from tutorial from local storage
4556
case'EDITOR_TUTORIAL_LOAD':
4657
consttutorial:G.Tutorial|null=this.context.tutorial.get()
@@ -113,8 +124,10 @@ class Channel implements Channel {
113124
}
114125
// send to webview
115126
publicsend=async(action:CR.Action)=>{
116-
117-
switch(action.type){
127+
console.log(`EDITOR SEND${action.type}`)
128+
// action may be an object.type or plain string
129+
constactionType:string=typeofaction==='string' ?action :action.type
130+
switch(actionType){
118131
case'TEST_PASS':
119132
// update local storage stepProgress
120133
constprogress=this.context.progress.setStepComplete(action.payload.stepId)

‎typings/index.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ export interface Action {
119119
meta?:any
120120
}
121121

122+
exportinterfaceEnvironment{
123+
machineId:string
124+
sessionId:string
125+
}
126+
122127
exportinterfaceMachineContext{
128+
env:Environment,
123129
tutorial:G.Tutorial|null,
124130
position:Position,
125131
progress:Progress,
@@ -136,10 +142,11 @@ export interface MachineStateSchema {
136142
Start:{
137143
states:{
138144
Startup:{}
145+
NewOrContinue:{}
139146
SelectTutorial:{}
140147
ContinueTutorial:{}
141-
}
142-
}
148+
},
149+
},
143150
Tutorial:{
144151
states:{
145152
Initialize:{}

‎web-app/src/Routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Routes = () => {
1919
return(
2020
<Workspace>
2121
<Router>
22-
<Routepath="Start.Startup">
22+
<Routepath={['Start.Startup','NewOrContinue']}>
2323
<LoadingPagetext="Launching..."/>
2424
</Route>
2525
<Routepath="Start.SelectTutorial">

‎web-app/src/components/Debugger/index.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import * as G from 'typings/graphql'
33
import*asCRfrom'typings'
44

55
interfaceProps{
6-
state:string
7-
tutorial:G.Tutorial
8-
position:CR.Position
9-
progress:CR.Progress
10-
children:React.ReactElement
6+
state:string
7+
tutorial:G.Tutorial
8+
env:CR.Environment
9+
position:CR.Position
10+
progress:CR.Progress
11+
children:React.ReactElement
1112
}
1213

13-
constDebugger=({ state, children, position, progress, tutorial}:Props)=>(
14+
constDebugger=({ state, children,env,position, progress, tutorial}:Props)=>(
1415
<divstyle={{backgroundColor:'#FFFF99',color:'black',padding:'.5rem'}}>
1516
<h4>state:{state}</h4>
16-
<p>tutorial:{tutorial ?tutorial.id :'none'}</p>
17+
<p>MachineId:{env.machineId}</p>
18+
<p>SessionId:{env.sessionId}</p>
19+
<p>tutorial:{tutorial ?tutorial.id :'none'}</p>
1720
<pstyle={{backgroundColor:'khaki',padding:'.5rem'}}>position:{JSON.stringify(position)}</p>
18-
<pstyle={{backgroundColor:'moccasin',padding:'.5rem'}}>progress:{JSON.stringify(progress)}</p>
19-
{children}
21+
<pstyle={{backgroundColor:'moccasin',padding:'.5rem'}}>progress:{JSON.stringify(progress)}</p>
22+
{children}
2023
</div>
2124
)
2225

‎web-app/src/components/Router/Route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interfaceProps{
22
children:any
3-
path:string
3+
path:string|string[]
44
}
55

66
constRoute=({ children}:Props)=>children

‎web-app/src/components/Router/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | nu
3232

3333
constchildArray=React.Children.toArray(children)
3434
for(constchildofchildArray){
35-
if(state.matches(child.props.path)){
35+
const{ path}=child.props
36+
letpathMatch
37+
if(typeofpath==='string'){
38+
pathMatch=state.matches(path)
39+
}elseif(Array.isArray(path)){
40+
pathMatch=path.some(p=>state.matches(p))
41+
}else{
42+
thrownewError(`Invalid route path${JSON.stringify(path)}`)
43+
}
44+
if(pathMatch){
3645
constelement=React.cloneElement<CloneElementProps>(child.props.children,{ send,context:state.context})
3746
returndebuggerWrapper(element,state)
3847
}

‎web-app/src/services/channel/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class Channel {
1515
require('./mock')
1616
}
1717

18+
// Loads VSCode webview connection with editor
1819
consteditor=acquireVsCodeApi()
20+
1921
this.editorSend=editor.postMessage
2022
}
2123
publicmachineSend=(action:Action|string)=>{/* */}
@@ -25,13 +27,19 @@ class Channel {
2527
this.machineSend=send
2628
}
2729
publicreceive=(event:ReceivedEvent)=>{
30+
// NOTE: must call event.data, cannot destructure. VSCode acts odd
2831
constaction=event.data
2932

3033
//@ts-ignore // ignore browser events from plugins
3134
if(action.source){return}
35+
3236
console.log(`CLIENT RECEIVE:${action.type}`,action)
37+
3338
// messages from core
3439
switch(action.type){
40+
case'ENV_LOAD':
41+
this.machineSend(action)
42+
return
3543
case'TUTORIAL_LOADED':
3644
// send action to state machine
3745
this.machineSend('TUTORIAL_LOADED')

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import * as CR from 'typings'
44
import*asselectorsfrom'../../selectors'
55

66
exportdefault{
7+
setEnv:assign({
8+
env:(context:CR.MachineContext,event:CR.MachineEvent)=>{
9+
returnevent.payload.env
10+
}
11+
}),
712
continueTutorial:assign({
813
tutorial:(context:CR.MachineContext,event:CR.MachineEvent)=>{
914
returnevent.payload.tutorial

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import client from '../../apollo'
66
importtutorialQueryfrom'../../apollo/queries/tutorial'
77

88
exportdefault{
9+
loadEnv(){
10+
channel.editorSend({
11+
type:'ENV_GET'
12+
})
13+
},
914
loadStoredTutorial(){
1015
// send message to editor to see if there is existing tutorial progress
1116
// in local storage on the editor

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
1212
id:'root',
1313
initial:'Start',
1414
context:{
15+
env:{machineId:'',sessionId:''},
1516
tutorial:null,
1617
position:{levelId:'',stageId:'',stepId:''},
1718
progress:{
@@ -24,9 +25,18 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
2425
states:{
2526
Start:{
2627
initial:'Startup',
27-
onEntry:['loadStoredTutorial'],
2828
states:{
2929
Startup:{
30+
onEntry:['loadEnv'],
31+
on:{
32+
ENV_LOAD:{
33+
target:'NewOrContinue',
34+
actions:['setEnv'],
35+
}
36+
}
37+
},
38+
NewOrContinue:{
39+
onEntry:['loadStoredTutorial'],
3040
on:{
3141
CONTINUE_TUTORIAL:{
3242
target:'ContinueTutorial',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp