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

load machineId, sessionId on client from editor#40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 1 commit intomasterfromfeature/github-oath
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletionssrc/channel/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,17 @@ class Channel implements Channel {

// console.log('EDITOR RECEIVED:', actionType)
switch (actionType) {
case 'ENV_GET':
this.send({
type: 'ENV_LOAD',
payload: {
env: {
machineId: vscode.env.machineId,
sessionId: vscode.env.sessionId,
}
}
})
return
// continue from tutorial from local storage
case 'EDITOR_TUTORIAL_LOAD':
const tutorial: G.Tutorial | null = this.context.tutorial.get()
Expand DownExpand Up@@ -113,8 +124,10 @@ class Channel implements Channel {
}
// send to webview
public send = async (action: CR.Action) => {

switch (action.type) {
console.log(`EDITOR SEND ${action.type}`)
// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type
switch (actionType) {
case 'TEST_PASS':
// update local storage stepProgress
const progress = this.context.progress.setStepComplete(action.payload.stepId)
Expand Down
11 changes: 9 additions & 2 deletionstypings/index.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,7 +119,13 @@ export interface Action {
meta?: any
}

export interface Environment {
machineId: string
sessionId: string
}

export interface MachineContext {
env: Environment,
tutorial: G.Tutorial | null,
position: Position,
progress: Progress,
Expand All@@ -136,10 +142,11 @@ export interface MachineStateSchema {
Start: {
states: {
Startup: {}
NewOrContinue: {}
SelectTutorial: {}
ContinueTutorial: {}
}
}
},
},
Tutorial: {
states: {
Initialize: {}
Expand Down
2 changes: 1 addition & 1 deletionweb-app/src/Routes.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ const Routes = () => {
return (
<Workspace>
<Router>
<Route path="Start.Startup">
<Route path={['Start.Startup', 'NewOrContinue']}>
<LoadingPage text="Launching..." />
</Route>
<Route path="Start.SelectTutorial">
Expand Down
21 changes: 12 additions & 9 deletionsweb-app/src/components/Debugger/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,20 +3,23 @@ import * as G from 'typings/graphql'
import * as CR from 'typings'

interface Props {
state: string
tutorial: G.Tutorial
position: CR.Position
progress: CR.Progress
children: React.ReactElement
state: string
tutorial: G.Tutorial
env: CR.Environment
position: CR.Position
progress: CR.Progress
children: React.ReactElement
}

const Debugger = ({ state, children, position, progress, tutorial }: Props) => (
const Debugger = ({ state, children,env,position, progress, tutorial }: Props) => (
<div style={{ backgroundColor: '#FFFF99', color: 'black', padding: '.5rem' }}>
<h4>state: {state}</h4>
<p>tutorial: {tutorial ? tutorial.id : 'none'}</p>
<p>MachineId: {env.machineId}</p>
<p>SessionId: {env.sessionId}</p>
<p>tutorial: {tutorial ? tutorial.id : 'none'}</p>
<p style={{ backgroundColor: 'khaki', padding: '.5rem' }}>position: {JSON.stringify(position)}</p>
<p style={{ backgroundColor: 'moccasin', padding: '.5rem' }}>progress: {JSON.stringify(progress)}</p>
{children}
<p style={{ backgroundColor: 'moccasin', padding: '.5rem' }}>progress: {JSON.stringify(progress)}</p>
{children}
</div>
)

Expand Down
2 changes: 1 addition & 1 deletionweb-app/src/components/Router/Route.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
interface Props {
children: any
path: string
path: string | string[]
}

const Route = ({ children }: Props) => children
Expand Down
11 changes: 10 additions & 1 deletionweb-app/src/components/Router/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,16 @@ const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | nu

const childArray = React.Children.toArray(children)
for (const child of childArray) {
if (state.matches(child.props.path)) {
const { path } = child.props
let pathMatch
if (typeof path === 'string') {
pathMatch = state.matches(path)
} else if (Array.isArray(path)) {
pathMatch = path.some(p => state.matches(p))
} else {
throw new Error(`Invalid route path ${JSON.stringify(path)}`)
}
if (pathMatch) {
const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
return debuggerWrapper(element, state)
}
Expand Down
8 changes: 8 additions & 0 deletionsweb-app/src/services/channel/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,9 @@ class Channel {
require('./mock')
}

// Loads VSCode webview connection with editor
consteditor=acquireVsCodeApi()

this.editorSend=editor.postMessage
}
publicmachineSend=(action:Action|string)=>{/* */}
Expand All@@ -25,13 +27,19 @@ class Channel {
this.machineSend=send
}
publicreceive=(event:ReceivedEvent)=>{
// NOTE: must call event.data, cannot destructure. VSCode acts odd
constaction=event.data

//@ts-ignore // ignore browser events from plugins
if(action.source){return}

console.log(`CLIENT RECEIVE:${action.type}`,action)

// messages from core
switch(action.type){
case'ENV_LOAD':
this.machineSend(action)
return
case'TUTORIAL_LOADED':
// send action to state machine
this.machineSend('TUTORIAL_LOADED')
Expand Down
5 changes: 5 additions & 0 deletionsweb-app/src/services/state/actions/context.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ import * as CR from 'typings'
import*asselectorsfrom'../../selectors'

exportdefault{
setEnv:assign({
env:(context:CR.MachineContext,event:CR.MachineEvent)=>{
returnevent.payload.env
}
}),
continueTutorial:assign({
tutorial:(context:CR.MachineContext,event:CR.MachineEvent)=>{
returnevent.payload.tutorial
Expand Down
5 changes: 5 additions & 0 deletionsweb-app/src/services/state/actions/editor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,11 @@ import client from '../../apollo'
import tutorialQuery from '../../apollo/queries/tutorial'

export default {
loadEnv() {
channel.editorSend({
type: 'ENV_GET'
})
},
loadStoredTutorial() {
// send message to editor to see if there is existing tutorial progress
// in local storage on the editor
Expand Down
12 changes: 11 additions & 1 deletionweb-app/src/services/state/machine.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
id: 'root',
initial: 'Start',
context: {
env: {machineId: '', sessionId: ''},
tutorial: null,
position: {levelId: '', stageId: '', stepId: ''},
progress: {
Expand All@@ -24,9 +25,18 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
states: {
Start: {
initial: 'Startup',
onEntry: ['loadStoredTutorial'],
states: {
Startup: {
onEntry: ['loadEnv'],
on: {
ENV_LOAD: {
target: 'NewOrContinue',
actions: ['setEnv'],
}
}
},
NewOrContinue: {
onEntry: ['loadStoredTutorial'],
on: {
CONTINUE_TUTORIAL: {
target: 'ContinueTutorial',
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp